Package org.fusesource.hawtjni.runtime
Class Library
java.lang.Object
org.fusesource.hawtjni.runtime.Library
Used 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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private static void
private String
private void
doLoad()
private boolean
extractAndLoad
(ArrayList<Throwable> errors, String customPath, String dir, String libName, String targetLibName) private File
private File
private File
final String
Deprecated.final String
static int
final String
Get the path to the native library loaded.Get the URL to the native library source that has been extracted (if it was extracted).static String
final String
Deprecated.final String
static String
final String
Deprecated.final String
getPlatformSpecifcResourcePath
(String platform) Deprecated.final String
final String
getPlatformSpecificResourcePath
(String platform) final String
Deprecated.final String
final String[]
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 directoryvoid
load()
Load the native library.private boolean
private boolean
loadLibrary
(ArrayList<Throwable> errors, String lib) private String
private static String
-
Field Details
-
STRATEGY_PROPERTY
- See Also:
-
STRATEGY_SHA1
- See Also:
-
STRATEGY_TEMP
- See Also:
-
SLASH
-
STRATEGY
-
name
-
version
-
classLoader
-
loaded
private boolean loaded -
nativeLibraryPath
-
nativeLibrarySourceUrl
-
-
Constructor Details
-
Library
-
Library
-
Library
-
Library
-
-
Method Details
-
version
-
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
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
-
getPlatform
-
getBitModel
public static int getBitModel() -
load
public void load()Load the native library. -
doLoad
private void doLoad() -
getArchSpecifcResourcePath
Deprecated. -
getArchSpecificResourcePath
-
getOperatingSystemSpecifcResourcePath
Deprecated. -
getOperatingSystemSpecificResourcePath
-
getPlatformSpecifcResourcePath
Deprecated. -
getPlatformSpecificResourcePath
-
getPlatformSpecifcResourcePath
Deprecated. -
getPlatformSpecificResourcePath
-
getResorucePath
Deprecated. -
getResourcePath
-
getLibraryFileName
-
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
-
file
-
map
-
extractSha1
-
computeSha1
- Throws:
NoSuchAlgorithmException
IOException
-
extractTemp
-
close
-
chmod755
-
load
-
loadLibrary
-