Java System.loadLibrary Dependencies

The third-party jar I'm using is trying to load my own library using System.loadLibrary. I think what happens is that one of the downloadable libraries depends on another native library. Pointing -Djava.library.path does not work properly in this case. The instructions from the application site put the DLL 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 has two parts.

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

  • Is there a good solution to solve this problem? I assume that I could explicitly call System.loadLibrary on all the DLLs (I'm not even sure if this will work), but I will have to call them in the correct order, otherwise I will have the same problem.

EDIT: I think it makes sense that this happens, and the best solution I have read so far is to use a dependent walker to understand it and then load it in reverse order ... but I'm open to the best deals. ..

thanks jeff

+6
java dll native
source share
1 answer

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

Some possible approaches:

  • A third-party bank is committed to loading its own dependencies, based on java.library.path.
  • Your code loads the DLLs needed by the third-party bank into reverse topographic sorting. However, this forces your code to indicate third-party jar dependencies. These dependencies may change.
  • You use the OS search DLL path (for example, using LD_LIBRARY_PATH on Unix / Linux / Mac or PATH on Windows). However, this may require running a script.
+4
source share

All Articles