原文地址:http://blog.csdn.net/quqibing001/article/details/51201768
Linux環境
系統變量LD_LIBRARY_PATH來添加Java.library.path
Windows
在系統->高級系統設置->環境變量里,在path變量里添加。
Eclipse
在Properties -> Run/Debug settings -> Arguments->VM arguments里添加:
-Djava.library.path=/home/abc/workspace/
IntelliJ Idea
Run/Debug Configurations的VM Options里添加:
-Djava.library.path=/home/abc/workspace/
程序動態添加
private static void loadJNILibDynamically() {
try {
System.setProperty("java.library.path", System.getProperty("java.library.path")
+ ":/home/abc/workspace/");
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
//C++動態鏈接庫 JNIC
System.loadLibrary("JNIC");
} catch (Exception e) {
// do nothing for exception
}
}