Package com.jme3.system
Class NativeLibraryLoader
java.lang.Object
com.jme3.system.NativeLibraryLoader
Utility class to register, extract, and load native libraries.
Register your own libraries via the
Example:
This will register the library. Load it via:
Register your own libraries via the
registerNativeLibrary(String, Platform, String, String)
method, for
each platform.
You can then extract this library (depending on platform), by
using loadNativeLibrary(java.lang.String, boolean)
.
Example:
NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Windows32, "native/windows/mystuff.dll"); NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Windows64, "native/windows/mystuff64.dll"); NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Linux32, "native/linux/libmystuff.so"); NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.Linux64, "native/linux/libmystuff64.so"); NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.MacOSX32, "native/macosx/libmystuff.jnilib"); NativeLibraryLoader.registerNativeLibrary("mystuff", Platform.MacOSX64, "native/macosx/libmystuff.jnilib");
This will register the library. Load it via:
NativeLibraryLoader.loadNativeLibrary("mystuff", true);It will load the right library automatically based on the platform.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
extractNativeLibraries
(Platform platform, File targetDir) static void
extractNativeLibrary
(Platform platform, String name, File targetDir) static File
Returns the folder where native libraries will be extracted.static File
getJarForNativeLibrary
(Platform platform, String name) static File[]
static boolean
Determines whether native Bullet is on the classpath.static void
loadNativeLibrary
(String name, boolean isRequired) First extracts the native library and then loads it.static void
registerNativeLibrary
(com.jme3.system.NativeLibrary library) Register a new native library.static void
registerNativeLibrary
(String name, Platform platform, String path) Register a new native library.static void
registerNativeLibrary
(String name, Platform platform, String path, String extractAsName) Register a new native library.static void
Specify a custom location where native libraries should be extracted to.
-
Method Details
-
registerNativeLibrary
public static void registerNativeLibrary(com.jme3.system.NativeLibrary library) Register a new native library. This simply registers a known library, the actual extraction and loading is performed by callingloadNativeLibrary(java.lang.String, boolean)
. -
registerNativeLibrary
public static void registerNativeLibrary(String name, Platform platform, String path, String extractAsName) Register a new native library. This simply registers a known library, the actual extraction and loading is performed by callingloadNativeLibrary(java.lang.String, boolean)
.- Parameters:
name
- The name / ID of the library (not OS or architecture specific).platform
- The platform for which the in-natives-jar path has been specified for.path
- The path inside the natives-jar or classpath corresponding to this library. Must be compatible with the platform argument.extractAsName
- The filename that the library should be extracted as, if null, use the same name as in the path.
-
registerNativeLibrary
Register a new native library. This simply registers a known library, the actual extraction and loading is performed by callingloadNativeLibrary(java.lang.String, boolean)
. This method should be called several times for each library name, each time specifying a different platform + path combination.- Parameters:
name
- The name / ID of the library (not OS or architecture specific).platform
- The platform for which the in-natives-jar path has been specified for.path
- The path inside the natives-jar or classpath corresponding to this library. Must be compatible with the platform argument.
-
isUsingNativeBullet
public static boolean isUsingNativeBullet()Determines whether native Bullet is on the classpath. Currently, the context extracts the native Bullet libraries, so this method is needed to determine if they are needed. Ideally, native Bullet would be responsible for its own natives.- Returns:
- True native bullet is on the classpath, false otherwise.
-
setCustomExtractionFolder
Specify a custom location where native libraries should be extracted to. Ensure this is a unique path not used by other applications to extract their libraries. Set tonull
to restore default functionality.- Parameters:
path
- Path where to extract native libraries.
-
getExtractionFolder
Returns the folder where native libraries will be extracted. This is automatically determined at run-time based on the following criteria:
- If a
custom extraction folder
has been specified, it is returned. - If the user can write to "java.io.tmpdir" folder, then it is used.
- Otherwise, the
storage folder
is used, to prevent collisions, a special subfolder is used callednatives_<hash>
where <hash> is computed automatically as the XOR of the classpath hash code and the last modified date of this class.
- Returns:
- Path where natives will be extracted to.
- If a
-
getJarsWithNatives
-
extractNativeLibraries
- Throws:
IOException
-
getJarForNativeLibrary
-
extractNativeLibrary
public static void extractNativeLibrary(Platform platform, String name, File targetDir) throws IOException - Throws:
IOException
-
loadNativeLibrary
First extracts the native library and then loads it.- Parameters:
name
- The name of the library to load.isRequired
- If true and the library fails to load, throw exception. If false, do nothing if it fails to load.
-