不同系统与程序修改java.library.path的位置(转)

原文地址: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
        }
}
posted @ 2017-01-17 14:45  huiy_小溪  阅读(12113)  评论(0编辑  收藏  举报