I use Java Web Start to run a Java application, which depends on some third-party libraries. Then these native libraries load another native library ( commonLib ) as their dependency using LoadLibrary / dlopen.
If you are not using Web Start, everything works as expected when your own libraries are in the same directory.
However, in Web Start, you need your own libraries to be packaged in a jar file and listed in the jnlp file I made:
<resources os="Windows"> <nativelib href="native/native-windows.jar" /> </resource> <resources os="Linux"> <nativelib href="native/native-linux.jar" /> </resources> <resources os="Mac OS X"> <nativelib href="native/native-osx.jar"/> </resources>
Native libraries load normally, but they cannot load their commonLib dependency - a C ++ call to LoadLibrary / dlopen fails because the file is present in some jar / cache folder not in the current library search path.
On Windows, I was able to solve this problem by preloading commonLib in Java before trying to load the JNI library, for example:
System.loadLibrary("commonLib"); System.loadLibrary("myNativeLib");
However, this approach does not work on OS X - dlopen does not work in native code. dlopen is apparently not smart enough not to try loading the library again if it is already loaded.
Is there a cross-platform way to batch load and load my own libraries that depend on other native libraries in Java Web Start?
java java-web-start jni
Karel petranek
source share