6

A 3rd party jar I use is trying to load a native library using System.loadLibrary. I think what is happening is that one of the libraries being loaded has a dependency on another native library. Pointing -Djava.library.path does not work properly in this case. The instructions from the app's site is put the dlls in the jre/bin directory, but I think this is a really bad idea (especially when trying to deploy to client sites).

So, this question really is 2 parts.

  1. Does it make sense that if a native lib tries to load another native lib that -Djava.library.path does not work?

  2. Is there a good solution for working around this problem? I guess I could explicitly call System.loadLibrary on all of the dlls (I'm not even sure if this would work), but I would need to make sure to call them in the correct order otherwise I'll have the same problem.

EDIT: I think this makes sense that it is happening, and the best solution I've read so far is to use dependency walker to figure it out and then load them in reverse order...but I'm open to better suggestions...

thanks, Jeff

1 Answer 1

4

Yes, it makes sense that native libraries do not use the Java property -Djava.library.path to link to other native libraries.

Some possible approaches:

  • The third-party jar is fixed to load its own dependencies, relying on java.library.path.
  • Your code loads the DLLs required by the third-party jar in a reverse topographic sort. However, this makes your code specify the dependencies of the third-party jar. Those dependencies might change.
  • You use the OS-specific DLL search path (e.g., using LD_LIBRARY_PATH on Unix/Linux/Mac, or PATH on Windows). However, this might require a startup script.
Sign up to request clarification or add additional context in comments.

2 Comments

I tried loading in the reverse sort, and it does work, so maybe I'll use that approach, unless there is some magic solution I am missing.
That's probably what I would do as well, in addition to maybe submitting a defect to the third party. If you're doing cross-platform software, the dynamically linked libraries may differ between platforms. Good luck!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.