java定义dll文件位置,为Netbeans中的本机dll提供自定义路径

I have a NetBeans platform application with 2 modules having different versions of same native library.

I added the native library inside release/module/lib folder under each module. [as per http://wiki.netbeans.org/DevFaqWrapperModules section: How do I include native libraries (.so or .dll) in my library wrapper module?]

But the problem is during the final build generation of the application, native libraries are copied to build\cluster\modules\lib folder. i.e only one version of my native library exists inside lib folder as both versions have same name. Now my question is can I specifically mention in Netbeans that jar (Version 1) should take native lib (ver1) and jar (Version 2) should refer to native lib (version 2).

解决方案

You can load a Native library file (.dll/Windows or .so/Linux) with two ways:

1) Load the file by providing the full path:

System.load("my/full/path/native.dll");

2) If your native file is located inside your Java Library Path:

System.loadLibrary("native");

Take notice that in the second case you only need to provide the name of your native file (without its extension).

The default Java Library Path depends on OS:

On Windows, it maps to PATH

On Linux, it maps to LD_LIBRARY_PATH

On OS X, it maps to DYLD_LIBRARY_PATH

If you want to set your own Java Library Path:

try {

System.setProperty("java.library.path","YOUR/PATH");

Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");

fieldSysPath.setAccessible(true);

fieldSysPath.set(null, null);

} catch (Exception ex) {

System.out.println("Failed to set Java Library Path: " + ex.getMessage);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值