Example usage for java.lang System mapLibraryName

List of usage examples for java.lang System mapLibraryName

Introduction

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

Prototype

public static native String mapLibraryName(String libname);

Source Link

Document

Maps a library name into a platform-specific string representing a native library.

Usage

From source file:pt.lsts.neptus.plugins.europa.EuropaUtils.java

protected static String locateLibrary(String lib) throws Exception {
    String lookFor = System.mapLibraryName(lib);
    Vector<String> path = new Vector<>();

    switch (CheckJavaOSArch.getOs()) {
    case "linux-x64":
        path.add(new File("libJNI/europa/x64").getAbsolutePath());
        break;//w  ww.  ja  v a  2s. co m
    default:
        break;
    }

    String ldPath = System.getenv("LD_LIBRARY_PATH"), europa = System.getenv("EUROPA_HOME");
    // Check for explicit info about europa location
    if (europa == null) {
        // Attempt to get PLASMA_HOME instead
        europa = System.getenv("PLASMA_HOME");
    }
    if (europa != null && new File(europa).isDirectory())
        path.add(europa + File.separator + "lib");
    // Get the java library path where jnilibs are expected to be
    path.addAll(Arrays.asList(System.getProperty("java.library.path").split(File.pathSeparator)));
    // finally add LD_LIBRARY_PATH if it exists
    if (ldPath != null) {
        path.addAll(Arrays.asList(ldPath.split(File.pathSeparator)));
    }

    // Now iterate through all these paths to locate the library
    for (String s : path) {
        File f = new File(s, lookFor);
        if (f.exists()) {
            // found it => return the fully qualified path
            return f.getAbsolutePath();
        }
    }
    // If we reach this point the library was nowhere to be found
    throw new FileNotFoundException("Library " + System.mapLibraryName(lib) + " was not found in "
            + StringUtils.join(path, File.pathSeparator));
}

From source file:ml.dmlc.xgboost4j.java.NativeLibLoader.java

/**
 * load native library, this method will first try to load library from java.library.path, then
 * try to load library in jar package.//from w  w w.j a  va 2  s.  co m
 *
 * @param libName library path
 * @throws IOException exception
 */
private static void smartLoad(String libName) throws IOException {
    addNativeDir(nativePath);
    try {
        System.loadLibrary(libName);
    } catch (UnsatisfiedLinkError e) {
        try {
            String libraryFromJar = nativeResourcePath + System.mapLibraryName(libName);
            loadLibraryFromJar(libraryFromJar);
        } catch (IOException ioe) {
            logger.error("failed to load library from both native path and jar");
            throw ioe;
        }
    }
}

From source file:net.sf.jpam.Pam.java

/**
 * @return the system dependent name of the shared library the Pam class is expecting.
 *//*w  w w  .ja  v a  2  s . co m*/
public static String getLibraryName() {
    return System.mapLibraryName(JPAM_SHARED_LIBRARY_NAME);
}

From source file:org.esa.s2tbx.dataio.gdal.GDALInstaller.java

private void processInstalledDistribution(Path gdalFolderPath, Path gdalBinFolderPath, OSCategory osCategory,
        String mapLibraryName) throws IOException {
    Path pathItem = gdalBinFolderPath.resolve(mapLibraryName);
    if (Files.exists(pathItem)) {
        // the library file exists on the local disk
        String libraryFileName = System.mapLibraryName("environment-variables");
        Path libraryFilePath = gdalFolderPath.resolve(libraryFileName);
        if (!Files.exists(libraryFilePath)) {
            String libraryFilePathFromSources = SRC_PATH + "/" + libraryFileName;
            URL libraryFileURLFromSources = getClass().getClassLoader().getResource(libraryFilePathFromSources);
            FileHelper.copyFile(libraryFileURLFromSources, libraryFilePath);
        }/*from w  ww.j ava  2s .  c  o  m*/
        NativeLibraryUtils.registerNativePaths(libraryFilePath.getParent());

        if (registerNativePaths(gdalBinFolderPath, osCategory)) {
            Path gdalAppsFolderPath = gdalBinFolderPath.resolve(APPS_PATH);

            String pathEnvironment = EnvironmentVariables.getEnvironmentVariable("PATH");
            boolean foundBinFolderInPath = findFolderInPathEnvironment(gdalBinFolderPath, pathEnvironment);
            if (!foundBinFolderInPath) {
                StringBuilder newPathValue = new StringBuilder();
                newPathValue.append("PATH").append("=").append(gdalBinFolderPath.toString())
                        .append(File.pathSeparator).append(gdalAppsFolderPath.toString())
                        .append(File.pathSeparator).append(pathEnvironment);
                EnvironmentVariables.setEnvironmentVariable(newPathValue.toString());
            }

            Path gdalDataFolderPath = gdalBinFolderPath.resolve(DATA_PATH);
            StringBuilder gdalDataValue = new StringBuilder();
            gdalDataValue.append("GDAL_DATA").append("=").append(gdalDataFolderPath.toString());
            EnvironmentVariables.setEnvironmentVariable(gdalDataValue.toString());

            Path gdalDriverFolderPath = gdalBinFolderPath.resolve(PLUGINS_PATH);
            StringBuilder gdalDriverValue = new StringBuilder();
            gdalDriverValue.append("GDAL_DRIVER_PATH").append("=").append(gdalDriverFolderPath.toString());
            EnvironmentVariables.setEnvironmentVariable(gdalDriverValue.toString());

            GdalInstallInfo gdalInstallInfo = GdalInstallInfo.INSTANCE;
            gdalInstallInfo.setLocations(gdalBinFolderPath, gdalAppsFolderPath, gdalDriverFolderPath,
                    gdalDataFolderPath);
        }
    } else {
        logger.log(Level.SEVERE, "The GDAL bin folder '" + gdalBinFolderPath.toString()
                + "' does not contain the library '" + mapLibraryName + "'.");
    }
}

From source file:org.opennms.netmgt.vmmgr.Starter.java

private void setDefaultProperties() {
    setupFileResourceProperty("opennms.library.jicmp", System.mapLibraryName("jicmp"),
            "Initialization of ICMP socket will likely fail.");
    setupFileResourceProperty("opennms.library.jrrd", System.mapLibraryName("jrrd"),
            "Initialization of RRD code will likely fail if the JniRrdStrategy is used.");
    setupFileResourceProperty("jcifs.properties", "jcifs.properties",
            "Initialization of JCIFS will likely fail or may be improperly configured.");
}

From source file:org.mule.module.launcher.MuleApplicationClassLoader.java

@Override
protected String findLibrary(String name) {
    String parentResolvedPath = super.findLibrary(name);

    if (null == parentResolvedPath) {
        final File library = new File(libraryPath, System.mapLibraryName(name));

        if (library.exists()) {
            parentResolvedPath = library.getAbsolutePath();
        }//ww w. ja v a 2  s  . c  o m
    }

    return parentResolvedPath;
}

From source file:edu.uw.apl.nativelibloader.NativeLoader.java

static private File findNativeLibrary(String prefix, String libName, Properties p) throws IOException {

    /*//from  w w  w.  jav a2 s. c  o m
      We compose the final resourceName in a way similar to the
      Maven convention for artifact file naming: GROUP/ARTIFACT.
      This is also similar to how .so files are named, except
      there the version trails the .so suffix (see e.g. /lib/ on
      any Unix system).
    */

    String nativeLibraryName = System.mapLibraryName(libName);
    String nativeLibraryPath = prefix.replaceAll("\\.", "/") + "/native/"
            + OSInfo.getNativeLibFolderPathForCurrentOS();

    /*
      Ensure the resourceName starts '/' so is not subject to any
      'package name modification' during Class.getResource(),
      Class.getResourceAsStream() calls (dots in the version
      string could get replaced with slash!)
    */
    String resourceName = "/" + nativeLibraryPath + "/" + nativeLibraryName;
    log.debug("ResourceName: " + resourceName);

    boolean haveNativeLib = haveResource(resourceName);
    if (!haveNativeLib) {
        if (OSInfo.getOSName().equals("Mac")) {
            // Fix for openjdk7 for Mac
            String altLibraryName = "lib" + libName + ".jnilib";
            resourceName = "/" + nativeLibraryPath + "/" + altLibraryName;
            log.debug("AltResourceName: " + resourceName);
            if (haveResource(resourceName)) {
                haveNativeLib = true;
            }
        }
    }

    if (!haveNativeLib)
        throw new IllegalStateException("Native library missing: " + resourceName);
    /*
    Temporary folder for the native library file.
    Use a user value of $prefix.$libName.tmpdir, or java.io.tmpdir
    by default
    */
    String tmpPath = getValue("path", prefix, libName, p);
    if (tmpPath == null)
        tmpPath = System.getProperty("java.io.tmpdir");
    File tmpDir = new File(tmpPath).getCanonicalFile();
    log.debug("Tempdir for native lib: " + tmpDir);
    return extractLibraryFile(resourceName, tmpDir);
}

From source file:com.googlecode.onevre.utils.ServerClassLoader.java

/**
 *
 * @see java.lang.ClassLoader#findLibrary(java.lang.String)
 *//*  w  ww.j  a v a  2  s . co  m*/
protected String findLibrary(String libname) {
    try {
        String name = System.mapLibraryName(libname + "-" + System.getProperty("os.arch"));
        URL url = getResourceURL(name);
        log.info("Loading " + name + " from " + url);
        if (url != null) {
            File jar = cachedJars.get(url);
            JarFile jarFile = new JarFile(jar);
            JarEntry entry = jarFile.getJarEntry(name);
            File library = new File(localLibDirectory, name);
            if (!library.exists()) {
                InputStream input = jarFile.getInputStream(entry);
                FileOutputStream output = new FileOutputStream(library);
                byte[] buffer = new byte[BUFFER_SIZE];
                int totalBytes = 0;
                while (totalBytes < entry.getSize()) {
                    int bytesRead = input.read(buffer);
                    if (bytesRead < 0) {
                        throw new IOException("Jar Entry too short!");
                    }
                    output.write(buffer, 0, bytesRead);
                    totalBytes += bytesRead;
                }
                output.close();
                input.close();
                jarFile.close();
            }
            return library.getAbsolutePath();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.trianacode.taskgraph.tool.ToolClassLoader.java

protected String findLibrary(String name) {
    log.debug("ToolClassLoader.findLibrary called with name:" + name);
    //String archDir = getNativeDir();
    String lib = System.mapLibraryName(name);
    URL url = this.getResource(lib);
    if (url == null) {
        return null;
    }//from   w  w  w  . j  a v a  2s  .  c o m
    try {
        return url.toURI().toString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.apache.taverna.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.java

/**
 * Constructs a classloader capable of finding both local jar and artifact dependencies.
 * Called when classloader sharing policy is set to 'workflow'.
 *
 * @return A {@link ClassLoader} capable of accessing all the dependencies (both local jar and artifact)
 */// w w  w  .ja v  a  2s .c  o m
private ClassLoader makeClassLoader(JsonNode json, String workflowID) {
    // Find all artifact dependencies
    //      HashSet<URL> urls = findDependencies(ARTIFACTS, configurationBean, workflowID);

    // Add all local jar dependencies
    HashSet<URL> urls = findDependencies(LOCAL_JARS, json, workflowID);

    // Create the classloader capable of loading both local jar and artifact dependencies
    ClassLoader parent = this.getClass().getClassLoader(); // this will be a LocalArtifactClassLoader

    return new URLClassLoader(urls.toArray(new URL[0]), parent) {

        // For finding native libraries that have to be stored in TAVERNA_HOME/lib
        @Override
        protected String findLibrary(String libname) {
            String filename = System.mapLibraryName(libname);
            File libraryFile = new File(libDir, filename);
            if (libraryFile.isFile()) {
                logger.info("Found library " + libname + ": " + libraryFile.getAbsolutePath());
                return libraryFile.getAbsolutePath();
            }
            return super.findLibrary(libname);
        }
    };
}