public class NativeUtils extends Object
A simple library class which helps with loading dynamic libraries stored in the JAR archive. These libraries usualy contain implementation of some methods in native code (using JNI - Java Native Interface).
Modifier and Type | Method and Description |
---|---|
static void |
addLibraryPath(String pathToAdd)
Adds the specified path to the java library path
|
static File |
createTempDir(String dirname) |
static void |
loadLibraryFromJar(String path,
File directory)
Loads library from current JAR archive
|
public static void loadLibraryFromJar(String path, File directory) throws IOException
The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after exiting. Method uses String as filename because the pathname is "abstract", not system-dependent.
path
- The path of file inside JAR as absolute path (beginning with '/'), e.g. /package/File.extIOException
- If temporary file creation or read/write operation failsIllegalArgumentException
- If source file (param path) does not existIllegalArgumentException
- If the path is not absolute or if the filename is shorter than three characters (restriction of File.createTempFile(java.lang.String, java.lang.String)
).public static void addLibraryPath(String pathToAdd) throws Exception
pathToAdd
- the path to addException
Copyright © 2017. All rights reserved.