Package org.fusesource.hawtjni.runtime
Class Library
- java.lang.Object
-
- org.fusesource.hawtjni.runtime.Library
-
public class Library extends java.lang.ObjectUsed to find and load a JNI library, eventually after having extracted it. It will search for the library in order at the following locations:- in the custom library path: If the "
library.${name}.path" System property is set to a directory, subdirectories are searched:- "
${platform}/${arch}" - "
${platform}" - "
${os}" - "
"
- as "
${name}-${version}" library name if the version can be determined. - as "
${name}" library name
- "
- system library path: This is where the JVM looks for JNI libraries by default.
- as "
${name}${bit-model}-${version}" library name if the version can be determined. - as "
${name}-${version}" library name if the version can be determined. - as "
${name}" library name
- as "
- classpath path: If the JNI library can be found on the classpath, it will get extracted
and then loaded. This way you can embed your JNI libraries into your packaged JAR files.
They are looked up as resources in this order:
- "
META-INF/native/${platform}/${arch}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library on different processor archs in the jar. - "
META-INF/native/${platform}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library in the jar. - "
META-INF/native/${os}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library in the jar but don't want to take bit model into account. - "
META-INF/native/${library[-version]}": Store your library here if your JAR is only going to embedding one platform library.
- The directory pointed to by the "
library.${name}.path" System property (if set) - a temporary directory (uses the "
java.io.tmpdir" System property)
- "
- "
${name}" is the name of library - "
${version}" is the value of "library.${name}.version" System property if set. Otherwise it is set to the ImplementationVersion property of the JAR's Manifest - "
${os}" is your operating system, for example "osx", "linux", or "windows" - "
${bit-model}" is "64" if the JVM process is a 64 bit process, otherwise it's "32" if the JVM is a 32 bit process - "
${arch}" is the architecture for the processor, for example "amd64" or "sparcv9" - "
${platform}" is "${os}${bit-model}", for example "linux32" or "osx64" - "
${library[-version]}": is the normal jni library name for the platform (eventually with-${version}) suffix. For example "${name}.dll" on windows, "lib${name}.jnilib" on OS X, and "lib${name}.so" on linux
- See Also:
System.mapLibraryName(String)
- in the custom library path: If the "
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoaderclassLoaderprivate booleanloadedprivate java.lang.Stringnameprivate java.lang.StringnativeLibraryPathprivate java.net.URLnativeLibrarySourceUrl(package private) static java.lang.StringSLASH(package private) static java.lang.StringSTRATEGYstatic java.lang.StringSTRATEGY_PROPERTYstatic java.lang.StringSTRATEGY_SHA1static java.lang.StringSTRATEGY_TEMPprivate java.lang.Stringversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidchmod755(java.io.File file)private static voidclose(java.io.Closeable file)private java.lang.StringcomputeSha1(java.io.InputStream is)private voiddoLoad()private booleanextractAndLoad(java.util.ArrayList<java.lang.Throwable> errors, java.lang.String customPath, java.lang.String dir, java.lang.String libName, java.lang.String targetLibName)private java.io.FileextractSha1(java.util.ArrayList<java.lang.Throwable> errors, java.net.URL source, java.lang.String prefix, java.lang.String suffix, java.io.File directory)private java.io.FileextractTemp(java.util.ArrayList<java.lang.Throwable> errors, java.net.URL source, java.lang.String prefix, java.lang.String suffix, java.io.File directory)private java.io.Filefile(java.lang.String... paths)java.lang.StringgetArchSpecifcResourcePath()Deprecated.java.lang.StringgetArchSpecificResourcePath()static intgetBitModel()java.lang.StringgetLibraryFileName()java.lang.StringgetNativeLibraryPath()Get the path to the native library loaded.java.net.URLgetNativeLibrarySourceUrl()Get the URL to the native library source that has been extracted (if it was extracted).static java.lang.StringgetOperatingSystem()java.lang.StringgetOperatingSystemSpecifcResourcePath()Deprecated.java.lang.StringgetOperatingSystemSpecificResourcePath()static java.lang.StringgetPlatform()java.lang.StringgetPlatformSpecifcResourcePath()Deprecated.java.lang.StringgetPlatformSpecifcResourcePath(java.lang.String platform)Deprecated.java.lang.StringgetPlatformSpecificResourcePath()java.lang.StringgetPlatformSpecificResourcePath(java.lang.String platform)java.lang.StringgetResorucePath()Deprecated.java.lang.StringgetResourcePath()java.lang.String[]getSpecificSearchDirs()Search directories for library:${platform}/${arch}to enable platform JNI library for different processor archs${platform}to enable platform JNI library${os}to enable OS JNI library no directoryvoidload()Load the native library.private booleanload(java.util.ArrayList<java.lang.Throwable> errors, java.io.File lib)private booleanloadLibrary(java.util.ArrayList<java.lang.Throwable> errors, java.lang.String lib)private java.lang.Stringmap(java.lang.String libName)private static java.lang.Stringversion(java.lang.Class<?> clazz)
-
-
-
Field Detail
-
STRATEGY_PROPERTY
public static final java.lang.String STRATEGY_PROPERTY
- See Also:
- Constant Field Values
-
STRATEGY_SHA1
public static final java.lang.String STRATEGY_SHA1
- See Also:
- Constant Field Values
-
STRATEGY_TEMP
public static final java.lang.String STRATEGY_TEMP
- See Also:
- Constant Field Values
-
SLASH
static final java.lang.String SLASH
-
STRATEGY
static final java.lang.String STRATEGY
-
name
private final java.lang.String name
-
version
private final java.lang.String version
-
classLoader
private final java.lang.ClassLoader classLoader
-
loaded
private boolean loaded
-
nativeLibraryPath
private java.lang.String nativeLibraryPath
-
nativeLibrarySourceUrl
private java.net.URL nativeLibrarySourceUrl
-
-
Constructor Detail
-
Library
public Library(java.lang.String name)
-
Library
public Library(java.lang.String name, java.lang.Class<?> clazz)
-
Library
public Library(java.lang.String name, java.lang.String version)
-
Library
public Library(java.lang.String name, java.lang.String version, java.lang.ClassLoader classLoader)
-
-
Method Detail
-
version
private static java.lang.String version(java.lang.Class<?> clazz)
-
getNativeLibraryPath
public java.lang.String getNativeLibraryPath()
Get the path to the native library loaded.- Returns:
- the path (should not be null once the library is loaded)
- Since:
- 1.16
-
getNativeLibrarySourceUrl
public java.net.URL getNativeLibrarySourceUrl()
Get the URL to the native library source that has been extracted (if it was extracted).- Returns:
- the url to the source (in classpath)
- Since:
- 1.16
-
getOperatingSystem
public static java.lang.String getOperatingSystem()
-
getPlatform
public static java.lang.String getPlatform()
-
getBitModel
public static int getBitModel()
-
load
public void load()
Load the native library.
-
doLoad
private void doLoad()
-
getArchSpecifcResourcePath
@Deprecated public final java.lang.String getArchSpecifcResourcePath()
Deprecated.
-
getArchSpecificResourcePath
public final java.lang.String getArchSpecificResourcePath()
-
getOperatingSystemSpecifcResourcePath
@Deprecated public final java.lang.String getOperatingSystemSpecifcResourcePath()
Deprecated.
-
getOperatingSystemSpecificResourcePath
public final java.lang.String getOperatingSystemSpecificResourcePath()
-
getPlatformSpecifcResourcePath
@Deprecated public final java.lang.String getPlatformSpecifcResourcePath()
Deprecated.
-
getPlatformSpecificResourcePath
public final java.lang.String getPlatformSpecificResourcePath()
-
getPlatformSpecifcResourcePath
@Deprecated public final java.lang.String getPlatformSpecifcResourcePath(java.lang.String platform)
Deprecated.
-
getPlatformSpecificResourcePath
public final java.lang.String getPlatformSpecificResourcePath(java.lang.String platform)
-
getResorucePath
@Deprecated public final java.lang.String getResorucePath()
Deprecated.
-
getResourcePath
public final java.lang.String getResourcePath()
-
getLibraryFileName
public final java.lang.String getLibraryFileName()
-
getSpecificSearchDirs
public final java.lang.String[] getSpecificSearchDirs()
Search directories for library:${platform}/${arch}to enable platform JNI library for different processor archs${platform}to enable platform JNI library${os}to enable OS JNI library- no directory
- Returns:
- the list
- Since:
- 1.15
-
extractAndLoad
private boolean extractAndLoad(java.util.ArrayList<java.lang.Throwable> errors, java.lang.String customPath, java.lang.String dir, java.lang.String libName, java.lang.String targetLibName)
-
file
private java.io.File file(java.lang.String... paths)
-
map
private java.lang.String map(java.lang.String libName)
-
extractSha1
private java.io.File extractSha1(java.util.ArrayList<java.lang.Throwable> errors, java.net.URL source, java.lang.String prefix, java.lang.String suffix, java.io.File directory)
-
computeSha1
private java.lang.String computeSha1(java.io.InputStream is) throws java.security.NoSuchAlgorithmException, java.io.IOException- Throws:
java.security.NoSuchAlgorithmExceptionjava.io.IOException
-
extractTemp
private java.io.File extractTemp(java.util.ArrayList<java.lang.Throwable> errors, java.net.URL source, java.lang.String prefix, java.lang.String suffix, java.io.File directory)
-
close
private static void close(java.io.Closeable file)
-
chmod755
private void chmod755(java.io.File file)
-
load
private boolean load(java.util.ArrayList<java.lang.Throwable> errors, java.io.File lib)
-
loadLibrary
private boolean loadLibrary(java.util.ArrayList<java.lang.Throwable> errors, java.lang.String lib)
-
-