问题
I have an Eclipse RCP application that uses some native libraries via JNI. These are shared libraries that dynamically link to each other. On Windows I put these libraries (as *.dll
files) next to the RCP launcher executable (*.exe
) file and load them via System.load("<absolute file path>")
. This works great, as the location of the launcher seems to be added to the java.library.path
so that dynamic linking between the libraries works.
On Linux, I get an UnsatisfiedLinkError
. The location of the launcher is not added to the java.library.path
. When I start the application from the terminal after setting the LD_LIBRARY_PATH
variable it works:
export LD_LIBRARY_PATH=.
./myApp
The location .
is the added to the java.library.path
. Is there a better way to do this? I want the users to just double click the launcher.
Setting -Djava.library.path=.
in the myApp.ini
file does also not work. I see it in the installation details but I still get an UnsatisfiedLinkError
.
回答1:
The most reliable way to find libraries is not using java.library.path
at all but finding them via Java code and load via System.load()
instead of System.loadLibrary()
. You can apply whatever logic you want for finding the native library (although it's probably best trying not to be too clever) and you could fall back to trying java.library.path
if your mechanism fails.
This will only work of course if the library doesn't depend on other libraries that might not be found.
来源:https://stackoverflow.com/questions/51289566/load-native-libraries-in-an-eclipse-rcp-application-on-linux