I am using Java Web Start to launch a Java application that depends on some third party native libraries. These native libraries then subsequently load another native library (commonLib
) as their dependency using LoadLibrary/dlopen.
When not using Web Start, everything works as expected when the native libraries are located in the same directory.
Web Start, however, requires the native libraries to be packed in a jar file and referenced in the jnlp file, which I did:
<!-- Windows OS -->
<resources os="Windows">
<nativelib href="native/native-windows.jar" />
</resource>
<!-- Linux OS -->
<resources os="Linux">
<nativelib href="native/native-linux.jar" />
</resources>
<!-- Mac OSX -->
<resources os="Mac OS X">
<nativelib href="native/native-osx.jar"/>
</resources>
The native libraries load fine but they fail to load their dependency commonLib
- the C++ LoadLibrary/dlopen call fails because the file is present in some jar/cache folder not on the current library search path.
On Windows, I was able to solve this problem by pre-loading commonLib
in Java before trying to load the JNI library, like so:
System.loadLibrary("commonLib");
System.loadLibrary("myNativeLib");
However, this approach doesn't work on OS X - dlopen in the native code fails. dlopen is apparently not smart enough not to try to load the library again if it is already loaded.
Is there a cross-platform way to pack and load native libraries that depend on other native libraries in Java Web Start?