简体   繁体   中英

Load native libraries in an Eclipse RCP application on Linux

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM