public class NativeLibraryUtil extends Object
Native libraries should be packaged into a single jar file, with the following directory and file structure:
natives linux_32 libxxx[-vvv].so linux_64 libxxx[-vvv].so linux_arm libxxx[-vvv].so linux_arm64 libxxx[-vvv].so osx_32 libxxx[-vvv].dylib osx_64 libxxx[-vvv].dylib windows_32 xxx[-vvv].dll windows_64 xxx[-vvv].dll aix_32 libxxx[-vvv].so libxxx[-vvv].a aix_64 libxxx[-vvv].so libxxx[-vvv].a
Here "xxx" is the name of the native library and "-vvv" is an optional version number.
Current approach is to unpack the native library into a temporary file and load from there.
Modifier and Type | Class and Description |
---|---|
static class |
NativeLibraryUtil.Architecture |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_SEARCH_PATH |
static String |
DELIM |
Constructor and Description |
---|
NativeLibraryUtil() |
Modifier and Type | Method and Description |
---|---|
static NativeLibraryUtil.Architecture |
getArchitecture()
Determines the underlying hardware platform and architecture.
|
static String |
getPlatformLibraryName(String libName)
Returns the full file name (without path) of the native library.
|
static String |
getPlatformLibraryPath(String searchPath)
Returns the path to the native library.
|
static String |
getVersionedLibraryName(Class<?> libraryJarClass,
String libName)
Returns the Maven-versioned file name of the native library.
|
static boolean |
loadNativeLibrary(Class<?> libraryJarClass,
String libName)
Deprecated.
|
static boolean |
loadNativeLibrary(JniExtractor jniExtractor,
String libName,
String... searchPaths)
Loads the native library.
|
static boolean |
loadVersionedNativeLibrary(Class<?> libraryJarClass,
String libName)
Loads the native library.
|
public static final String DELIM
public static final String DEFAULT_SEARCH_PATH
public static NativeLibraryUtil.Architecture getArchitecture()
public static String getPlatformLibraryPath(String searchPath)
searchPath
- the path to search for <platform> directory.
Pass in null
to get default path
(natives/<platform>).public static String getPlatformLibraryName(String libName)
libName
- name of librarypublic static String getVersionedLibraryName(Class<?> libraryJarClass, String libName)
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<inherited>true</inherited> *
<configuration>
<archive>
<manifest>
<packageName>com.example.package</packageName>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> *
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
* = necessary to save version information in manifest
libraryJarClass
- any class within the library-containing jarlibName
- name of librarypublic static boolean loadVersionedNativeLibrary(Class<?> libraryJarClass, String libName)
libraryJarClass
- any class within the library-containing jarlibName
- name of librarypublic static boolean loadNativeLibrary(JniExtractor jniExtractor, String libName, String... searchPaths)
jniExtractor
- the extractor to uselibName
- name of librarysearchPaths
- a list of additional paths to search for the library@Deprecated public static boolean loadNativeLibrary(Class<?> libraryJarClass, String libName)
libraryJarClass
- any class within the library-containing jarlibName
- name of libraryCopyright © 2015–2022 SciJava. All rights reserved.