Example usage for java.lang UnsatisfiedLinkError UnsatisfiedLinkError

List of usage examples for java.lang UnsatisfiedLinkError UnsatisfiedLinkError

Introduction

In this page you can find the example usage for java.lang UnsatisfiedLinkError UnsatisfiedLinkError.

Prototype

public UnsatisfiedLinkError(String s) 

Source Link

Document

Constructs an UnsatisfiedLinkError with the specified detail message.

Usage

From source file:brut.util.Jar.java

public static void load(String libPath) {
    if (mLoaded.contains(libPath)) {
        return;//ww w .ja  v  a  2 s . c o m
    }

    File libFile;
    try {
        libFile = getResourceAsFile(libPath);
    } catch (BrutException ex) {
        throw new UnsatisfiedLinkError(ex.getMessage());
    }

    System.load(libFile.getAbsolutePath());
}

From source file:com.lfv.lanzius.application.FootSwitchController.java

public void start() throws NoSuchPortException, PortInUseException {
    if (!isStarted) {
        log.debug("Starting interface " + footSwitchInterface);

        // Setup com port
        serialPort = null;//  w  w w  .  j  a v a 2 s . c o  m
        if (isFTDI) {
            // Check ftsw library for correct version
            int version = 0;
            try {
                version = getSwitchVersion();
            } catch (UnsatisfiedLinkError err) {
            }

            if (version != FTSW_VERSION)
                throw new UnsatisfiedLinkError(
                        "Outdated version of the ftsw library! Update to a newer version, at least 2.1!");

            setSwitchFunction(isInverted);
        } else {
            CommPortIdentifier ci = CommPortIdentifier.getPortIdentifier(footSwitchInterface);
            CommPort port = ci.open("ftsw", 1000);
            serialPort = (SerialPort) port;

            // Ugly hack for making it work properly under linux
            boolean paramsSet = false;
            System.out.println("");

            try {
                serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
                paramsSet = true;
            } catch (UnsupportedCommOperationException ex) {
            }
            if (!paramsSet) {
                try {
                    serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                            SerialPort.PARITY_NONE);
                    paramsSet = true;
                } catch (UnsupportedCommOperationException ex) {
                    log.error("Unable to set serial parameters! ", ex);
                }
            }
        }

        isWaiting = true;
        isStarted = true;
        thread = new Thread(this, "DTfootswitch");
        thread.setDaemon(true);
        thread.start();
    }
}

From source file:com.izforge.izpack.util.Librarian.java

/**
 * Loads a library./*w  ww  .  j a v a 2  s  . co m*/
 *
 * @param name   the library name
 * @param client the native library client
 * @throws UnsatisfiedLinkError if the library cannot be loaded
 */
public synchronized void loadLibrary(String name, NativeLibraryClient client) throws UnsatisfiedLinkError {
    name = strip(name);
    if (!trackList.contains(name)) {
        // no attempt has been made to load the library yet
        boolean loaded = loadArchSpecificLibrary(name, client);
        if (!loaded) {
            String name64 = name + "_x64";
            loaded = loadArchSpecificLibrary(name64, client);
        }
        if (loaded) {
            trackList.add(name);
        } else {
            throw new UnsatisfiedLinkError("Failed to load library: " + name);

        }
    }
}

From source file:com.microsoft.tfs.jni.loader.NativeLoader.java

/**
 * Loads the given library name using the enhanced method documented in this
 * class's Javadoc. If a library is already loaded, subsequent calls to this
 * method with the same library name will be ignored.
 *
 * @param libraryName// w  w  w  . jav a 2 s.  c o m
 *        the library name (short name, not including extension or "lib"
 *        prefix). Not null or empty.
 * @throws UnsatisfiedLinkError
 *         if a library that maps to the given library name cannot be found.
 * @throws IOException
 *         if an error occured reading a native library resource or writing
 *         it to a temporary location.
 */
public static void loadLibrary(final String libraryName) throws UnsatisfiedLinkError, IOException {
    Check.notNullOrEmpty(libraryName, "libraryName"); //$NON-NLS-1$

    log.debug(MessageFormat.format("Loading library {0}", libraryName)); //$NON-NLS-1$

    final String osgiOperatingSystem = getOSGIOperatingSystem();
    if (osgiOperatingSystem == null) {
        throw new UnsatisfiedLinkError(
                "Could not determine OSGI-style operating system name for resource path construction"); //$NON-NLS-1$
    }

    String osgiArchitecture = getOSGIArchitecture();
    if (osgiArchitecture == null) {
        throw new UnsatisfiedLinkError(
                "Could not determine OSGI-style architecture for resource path construction"); //$NON-NLS-1$
    }

    /*
     * Even though we make sure the OSGI architecture string we loaded is
     * non-null, we want to use a null architecture string for loading if
     * we're on Mac OS X. This is because OS X has "fat" libraries and
     * executables, and we don't want to build a path containing an
     * architecture.
     */
    if (Platform.isCurrentPlatform(Platform.MAC_OS_X)) {
        osgiArchitecture = null;
    }

    /*
     * If the system property is set, only load from that location (do not
     * fallback to other locations).
     */
    final String loadFromDirectory = System.getProperty(NATIVE_LIBRARY_BASE_DIRECTORY_PROPERTY);
    if (loadFromDirectory != null) {
        log.debug(MessageFormat.format("Property {0} set to {1}; only looking there for native libraries", //$NON-NLS-1$
                NATIVE_LIBRARY_BASE_DIRECTORY_PROPERTY, loadFromDirectory));

        // Throws on error.
        loadLibraryFromDirectory(libraryName, loadFromDirectory, osgiOperatingSystem, osgiArchitecture);

        // Success.
        return;
    }

    /*
     * Use the Java built-in mechanisms for finding the library. This call
     * obeys java.library.path, LD_LIBRARY_PATH (Unix), DLL search path
     * (Windows), and more. It will throw if it fails.
     */
    System.loadLibrary(libraryName);
    log.info(MessageFormat.format("Loaded {0} with System.loadLibrary()", libraryName)); //$NON-NLS-1$
}

From source file:com.microsoft.tfs.jni.loader.NativeLoader.java

/**
 * Loads a native library from a directory.
 *
 * @param libraryName/*  w  ww .  j  a v a 2  s  . c o  m*/
 *        the library name (short name, not including extension or "lib"
 *        prefix). Not null or empty.
 * @param directory
 *        the path to the directory (not null).
 * @param osgiOperatingSystem
 *        the OSGI-style operating system name to match resources on (not
 *        null or empty).
 * @param osgiArchitecture
 *        the OSGI-style architecture name. May be null or empty to omit the
 *        architecture string from the resource path during the search. Mac
 *        OS X uses "fat" shared libraries that support multiple
 *        architectures, and would omit this parameter.
 * @throws UnsatisfiedLinkError
 *         if a library that maps to the given library name cannot be found.
 */
private static void loadLibraryFromDirectory(final String libraryName, final String directory,
        final String osgiOperatingSystem, final String osgiArchitecture) {
    Check.notNullOrEmpty(libraryName, "libraryName"); //$NON-NLS-1$
    Check.notNull(directory, "directory"); //$NON-NLS-1$
    Check.notNull(osgiOperatingSystem, "osgiOperatingSystem"); //$NON-NLS-1$

    final File libraryDirectory = new File(directory);

    if (libraryDirectory.exists() == false) {
        throw new UnsatisfiedLinkError(MessageFormat.format("Native library base directory {0} does not exist", //$NON-NLS-1$
                libraryDirectory.getAbsolutePath()));
    }

    if (libraryDirectory.isDirectory() == false) {
        throw new UnsatisfiedLinkError(
                MessageFormat.format("Native library base directory {0} is not a directory", //$NON-NLS-1$
                        libraryDirectory.getAbsolutePath()));
    }

    /*
     * Compute the subdirectory (i.e. "linux/ppc") inside the base
     * directory.
     */

    File fullDirectory = new File(libraryDirectory, osgiOperatingSystem);

    if (osgiArchitecture != null && osgiArchitecture.length() > 0) {
        fullDirectory = new File(fullDirectory, osgiArchitecture);
    }

    /*
     * Convert "fun" into "libfun.so" or "fun.dll" or whatever, depending on
     * platform.
     *
     * Oracle broke mapLibraryName on Java 7 so that it returns
     * libname.dylib instead of libname.jnilib. (System.loadLibrary
     * continues to use .jnilib, however, so this wasn't a change of the
     * expected extension, it's just broken.) So we need to transform names
     * ourselves on Mac OS.
     */
    final String mappedLibraryName;

    if (Platform.isCurrentPlatform(Platform.MAC_OS_X)) {
        mappedLibraryName = "lib" + libraryName + ".jnilib"; //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        mappedLibraryName = System.mapLibraryName(libraryName);
    }

    /*
     * Construct the full path.
     */

    final File fullLibraryFile = new File(fullDirectory, mappedLibraryName);

    if (fullLibraryFile.exists() == false) {
        throw new UnsatisfiedLinkError(MessageFormat.format("Native library file {0} does not exist", //$NON-NLS-1$
                fullLibraryFile.getAbsolutePath()));
    }

    if (fullLibraryFile.isDirectory() == true) {
        throw new UnsatisfiedLinkError(MessageFormat.format("Native library file {0} is a directory", //$NON-NLS-1$
                fullLibraryFile.getAbsolutePath()));
    }

    log.debug(
            MessageFormat.format("Trying to load native library file {0}", fullLibraryFile.getAbsolutePath())); //$NON-NLS-1$

    System.load(fullLibraryFile.getAbsolutePath());
    log.debug(MessageFormat.format("Loaded {0} from user-specified directory", //$NON-NLS-1$
            fullLibraryFile.getAbsolutePath()));

    return;
}

From source file:JNLPAppletLauncher.java

/**
 * Method called by an extension such as JOGL or Java 3D to load the
 * specified library. Applications and applets should not call this method.
 *
 * @param libraryName name of the library to be loaded
 *
 * @throws SecurityException if the caller does not have permission to
 * call System.load//from w w w .ja v  a2 s .  c  o m
 */
public static void loadLibrary(String libraryName) {
    if (VERBOSE) {
        System.err.println("-----------");
        Thread.dumpStack();
    }

    if (DEBUG) {
        System.err.println("JNLPAppletLauncher.loadLibrary(\"" + libraryName + "\")");
    }

    String fullLibraryName = (String) nativeLibMap.get(libraryName);
    if (fullLibraryName == null) {
        // Throw UnsatisfiedLinkError to try to match behavior of System.loadLibrary()
        throw new UnsatisfiedLinkError(libraryName);
    }

    if (DEBUG) {
        System.err.println("    loading: " + fullLibraryName + "");
    }

    System.load(fullLibraryName);
}

From source file:org.nd4j.linalg.api.buffer.util.LibUtils.java

/**
 * Loads the specified library. The full name of the library
 * is created by calling {@link LibUtils#createLibName(String)}
 * with the given argument. The method will attempt to load
 * the library as a as a resource (for usage within a JAR),
 * and, if this fails, using the usual System.loadLibrary
 * call.// w  ww. j av  a  2s  .c om
 *
 * @param baseName The base name of the library
 * @throws UnsatisfiedLinkError if the native library
 * could not be loaded.
 */
public static void loadLibrary(String baseName) {
    String libName = LibUtils.createLibName(baseName);

    Throwable throwable = null;
    final boolean tryResource = true;
    if (tryResource) {
        try {
            loadLibraryResource(libName);
            return;
        } catch (Throwable t) {
            throwable = t;
        }
    }

    try {
        System.loadLibrary(libName);
        return;
    } catch (Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        pw.println(
                "Error while loading native library \"" + libName + "\" with base name \"" + baseName + "\"");
        pw.println("Operating system name: " + System.getProperty("os.name"));
        pw.println("Architecture         : " + System.getProperty("os.arch"));
        pw.println("Architecture bit size: " + System.getProperty("sun.arch.data.model"));

        if (throwable != null) {
            pw.println("Stack trace from the attempt to " + "load the library as a resource:");
            throwable.printStackTrace(pw);
        }

        pw.println("Stack trace from the attempt to " + "load the library as a file:");
        t.printStackTrace(pw);

        pw.flush();
        pw.close();
        throw new UnsatisfiedLinkError("Could not load the native library.\n" + sw.toString());
    }
}

From source file:sf.net.experimaestro.tasks.ServerTask.java

/**
 * Server thread/*from  w  w w  .jav  a 2s  .  com*/
 */
public int execute() throws Throwable {
    if (configuration == null || configuration.getFile() == null) {
        final String envConfFile = System.getenv("EXPERIMAESTRO_CONFIG_FILE");
        File file = null;
        if (envConfFile != null) {
            file = new File(envConfFile);
            LOGGER.info("Using configuration file set in environment: '" + file + "'");
        } else {
            file = new File(new File(System.getProperty("user.home"), ".experimaestro"), "settings.ini");
            LOGGER.info("Using the default configuration file " + file);
        }
        assert file != null;
        configuration = new HierarchicalINIConfiguration(file);
    }
    LOGGER.info("Reading configuration from " + configuration.getFileName());

    // --- Get the server settings
    ServerSettings serverSettings = new ServerSettings(configuration.subset("server"));

    // --- Get the port
    port = configuration.getInt("server.port", 8080);
    LOGGER.info("Starting server on port %d", port);

    // --- Set up the task manager
    final String property = configuration.getString("server.database");
    if (property == null)
        throw new IllegalArgumentException("No 'database' in 'server' section of the configuration file");

    File taskmanagerDirectory = new File(property);
    scheduler = new Scheduler(taskmanagerDirectory);

    // Early initialization to detect errors
    XPMContext.init();

    // Main repository
    final Repositories repositories = new Repositories(new File("/").toPath());

    Server webServer = new Server();

    // TCP-IP socket
    ServerConnector connector = new ServerConnector(webServer);
    connector.setPort(port);
    webServer.addConnector(connector);

    // Unix domain socket
    if (configuration.containsKey(KEY_SERVER_SOCKET)) {
        // TODO: move this to the target class
        String libraryPath = System.getProperty("org.newsclub.net.unix.library.path");
        if (libraryPath == null) {
            URL url = ServerTask.class.getProtectionDomain().getCodeSource().getLocation();
            File file = new File(url.toURI());
            while (file != null && !new File(file, "native-libs").exists()) {
                file = file.getParentFile();
            }
            if (file == null)
                throw new UnsatisfiedLinkError("Cannot find the native-libs directory");
            file = new File(file, "native-libs");

            LOGGER.info("Using path for junixsocket library [%s]", file);
            System.setProperty("org.newsclub.net.unix.library.path", file.getAbsolutePath());
        }

        String socketSpec = configuration.getString(KEY_SERVER_SOCKET);
        UnixSocketConnector unixSocketConnector = new UnixSocketConnector(webServer);
        unixSocketConnector.setSocketFile(new File(socketSpec));
        webServer.addConnector(unixSocketConnector);
    }

    HandlerList collection = new HandlerList();

    // --- Non secure context

    ServletContextHandler nonSecureContext = new ServletContextHandler(collection, "/");
    nonSecureContext.getServletHandler().setEnsureDefaultServlet(false); // no 404 default page
    nonSecureContext.addServlet(new ServletHolder(new NotificationServlet(serverSettings, scheduler)),
            "/notification/*");

    // --- Sets the password on all pages

    ServletContextHandler context = new ServletContextHandler(collection, "/");
    ConstraintSecurityHandler csh = getSecurityHandler();
    context.setSecurityHandler(csh);

    // --- Add the JSON RPC servlet

    final JsonRPCServlet jsonRpcServlet = new JsonRPCServlet(webServer, scheduler, repositories);
    JsonRPCMethods.initMethods();
    final ServletHolder jsonServletHolder = new ServletHolder(jsonRpcServlet);
    context.addServlet(jsonServletHolder, JSON_RPC_PATH);

    // --- Add the web socket servlet

    final XPMWebSocketServlet webSocketServlet = new XPMWebSocketServlet(webServer, scheduler, repositories);
    final ServletHolder webSocketServletHolder = new ServletHolder(webSocketServlet);
    context.addServlet(webSocketServletHolder, "/web-socket");

    // --- Add the status servlet

    context.addServlet(new ServletHolder(new StatusServlet(serverSettings, scheduler)), "/status/*");

    // --- Add the status servlet

    final ServletHolder taskServlet = new ServletHolder(
            new TasksServlet(serverSettings, repositories, scheduler));
    context.addServlet(taskServlet, "/tasks/*");

    // --- Add the JS Help servlet

    context.addServlet(new ServletHolder(new JSHelpServlet(serverSettings)), "/jshelp/*");

    // --- Add the default servlet

    context.addServlet(new ServletHolder(new ContentServlet(serverSettings)), "/*");

    // final URL warUrl =
    // this.getClass().getClassLoader().getResource("web");
    // final String warUrlString = warUrl.toExternalForm();
    // server.setHandler(new WebAppContext(warUrlString, "/"));

    // --- Sets the main handler
    webServer.setHandler(collection);

    // --- start the server and wait

    webServer.start();

    if (wait) {
        webServer.join();
    }

    LOGGER.info("Servers are stopped. Clean exit!");

    return 0;
}

From source file:us.ihmc.rtps.impl.fastRTPS.FastRTPSDomain.java

private FastRTPSDomain() {
    try {/*from  w w  w  .j a  va2 s. c om*/
        NativeLibraryLoader.loadLibrary("us.ihmc.rtps.impl.fastRTPS", "FastRTPSWrapper");
    } catch (UnsatisfiedLinkError e) {
        if (SystemUtils.IS_OS_WINDOWS) {
            throw new UnsatisfiedLinkError(
                    "Cannot load library, make sure to install Microsoft Visual C++ 2017 Redistributable (x64) (https://go.microsoft.com/fwlink/?LinkId=746572) ");
        } else {
            throw e;
        }
    }
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        stopAll();
    }, "IHMCPubSub-FastRTPSDomain-StopAll"));
}