Reputation: 644
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).
Upvotes: 1
Views: 3730
Reputation: 733
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);
}
Upvotes: 3