views:

68

answers:

1

I would like to ship my application as a self-contained jar file. The jar file should contain all the class files, as well as two shared libraries. One of these shared libraries is written for the JNI and is essentially an indirection to the other one (which is 100% C).

I have first tried running my jar file without the libraries, but having them accessible through the LD_LIBRARY_PATH environment variable. That worked fine.

I then put the JNI library into the jar file. I have read about loading libraries from jar files by copying them first to some temporary directory, and that worked well for me (note that the 100% C library was, I suppose, loaded as before).

Now I want to put both libraries into the jar, but I don't understand how I can make sure that they will both be loaded. Sure I can copy them both to a temporary directory, but when I load the "indirection" one, it always gives me:

java.lang.UnsatisfiedLinkError: /tmp/.../libindirect.so: /libpure.so: cannot open shared object file: No such file or directory

I've tried to force the JVM to load the "100% C" library first by explicitely calling System.load(...) on its temporary file, but that didn't work better. I suspect the system is looking for it when resolving the links in libindirect.so but doesn't care about what the JVM loaded.

Can anyone help me on that one?

Thanks

+1  A: 

One way would be to spawn another Java process from the first, generating the appropriate invocation script.

  1. The jar is invoked by the user
  2. The libraries are extracted to a temp directory
  3. A (bash) script is written to the temp directory
    • this sets/exports the necessary environment variables
    • this launches the second JRE instance
  4. The code makes the script executable
  5. The code invokes the script

I know, spawning two JRE instances to launch one app would not be my first choice either.

McDowell
Sorry, I'm not sure I understand what you mean by "the appropriate invocation script"? I don't see how a second process would help in finding the "100% C" library.
Philip
@Philip - I've added more detail, but as I said before, it is a far from ideal suggestion.
McDowell
OK I see what you mean now. I thing if I have to resort to something like this I'd rather have a bash script that runs the whole thing (and unpacks from the jar file). For now I'll keep hoping there's a better way :)
Philip