public final class NativeLibraryLoader
extends java.lang.Object
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)
.
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");
NativeLibraryLoader.loadNativeLibrary("mystuff", true);It will load the right library automatically based on the platform.
Modifier and Type | Method and Description |
---|---|
static void |
extractNativeLibraries(Platform platform,
java.io.File targetDir) |
static void |
extractNativeLibrary(Platform platform,
java.lang.String name,
java.io.File targetDir) |
static java.io.File |
getExtractionFolder()
Returns the folder where native libraries will be extracted.
|
static java.io.File |
getJarForNativeLibrary(Platform platform,
java.lang.String name) |
static java.io.File[] |
getJarsWithNatives() |
static boolean |
isUsingNativeBullet()
Determines whether native Bullet is on the classpath.
|
static void |
loadNativeLibrary(java.lang.String name,
boolean isRequired)
First extracts the native library and then loads it.
|
static void |
registerNativeLibrary(java.lang.String name,
Platform platform,
java.lang.String path)
Register a new known JNI library.
|
static void |
registerNativeLibrary(java.lang.String name,
Platform platform,
java.lang.String path,
java.lang.String extractAsName)
Register a new known library.
|
static void |
setCustomExtractionFolder(java.lang.String path)
Specify a custom location where native libraries should
be extracted to.
|
public static void registerNativeLibrary(java.lang.String name, Platform platform, java.lang.String path, java.lang.String extractAsName)
loadNativeLibrary(java.lang.String, boolean)
.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.public static void registerNativeLibrary(java.lang.String name, Platform platform, java.lang.String path)
loadNativeLibrary(java.lang.String, boolean)
.
This method should be called several times for each library name,
each time specifying a different platform + path combination.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.public static boolean isUsingNativeBullet()
public static void setCustomExtractionFolder(java.lang.String path)
null
to restore default
functionality.path
- Path where to extract native libraries.public static java.io.File getExtractionFolder()
custom
extraction folder
has been specified, it is returned.
storage folder
is used, to prevent collisions, a special subfolder is used
called natives_<hash>
where <hash>
is computed automatically as the XOR of the classpath hash code
and the last modified date of this class.
public static java.io.File[] getJarsWithNatives()
public static void extractNativeLibraries(Platform platform, java.io.File targetDir) throws java.io.IOException
java.io.IOException
public static java.io.File getJarForNativeLibrary(Platform platform, java.lang.String name)
public static void extractNativeLibrary(Platform platform, java.lang.String name, java.io.File targetDir) throws java.io.IOException
java.io.IOException
public static void loadNativeLibrary(java.lang.String name, boolean isRequired)
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.