How to load a library that depends on another library, all from a jar file

I would like to send my application as a standalone jar file. The jar file must contain all class files, as well as two shared libraries. One of these shared libraries is written for JNI and is essentially indirect to the other (which is 100% C).

I first tried to run the jar file without libraries, but had them available through the LD_LIBRARY_PATH environment variable. This worked fine.

Then I put the JNI library in the jar file. I read about loading libraries from jar files, copying them first to some temporary directory, and it worked for me (note that the 100% C library was, I suppose, still loaded).

Now I want to put both libraries in a jar, but I don’t understand how I can make sure that both of them will be loaded. Of course, I can copy them to a temporary directory, but when I load the "indirect" one, it always gives me:

java.lang.UnsatisfiedLinkError: / tmp /.../ libindirect.so:/libpure.so: cannot open a shared objects file: there is no such file or directory

I tried to get the JVM to load the "100% C" library first, explicitly calling System.load (...) in its temporary file, but that didn't help. I suspect the system is looking for it when resolving links in libindirect.so, but does not care about loading the JVM.

Can anyone help me on this?

thanks

+6
java jar dll shared-libraries jni
source share
2 answers

One way would be to create another Java process from the first by creating an appropriate script call.

  • The box is called by the user
  • Libraries are extracted to a temporary directory
  • A (bash) script is written to temp directory
    • this sets / exports the necessary environment variables
    • this starts the second instance of the jre
  • The code makes an executable script
  • The code calls the script

I know that creating two JRE instances to run a single application will not be my first choice.

+2
source share

If you are using the Eclipse IDE, this answer may help you.

I had the same problem in eclipse windows that I could not add dependent .class files from JNI. After some time searching, I found out that "Known error inside Eclipse" . To solve this problem, I put all the code in NetBeans IDE.

Unable to add all class files from JNI folder in Eclipse (JAVA, Windows 7)

0
source share

All Articles