1

I have a Java application that relies on some legacy code written in C, which it accesses via JNI. The native libraries are stored in a sub-directory (actually, there are two sub-dirs: one with 32-bit libraries and one with 64-bit).

In Windows, the following command line form works fine:

java -Djava.library.path=nativelib64 -classpath myapp.jar;jni_lib.jar MyApplication

but the equivalents on AIX and Linux (basically with the semi-colon in the classpath replaced with a colon) are failing with UnsatisfiedLinkErrors - I'm having to resort to setting the LIBPATH or LD_LIBRARY_PATH explicitly before the call, as nothing I've tried setting -Djava.library.path to (e.g. "nativelib64", "./nativelib64", "/full/path/to/myappdir/nativelib64") seems to be working.

Do the UNIX versions of the JVM not support setting the java.library.path property from the command line?

4
  • What kind of java variable is working? Commented Apr 19, 2013 at 11:11
  • 1
    Does your native library depend on other shared libraries located in the same sub directory? Commented Apr 19, 2013 at 11:24
  • @Andreas yes it does, and your comment reminds me that the ULE appears to be happening when it's trying to link across from one native lib to another. I'm guessing this is a clue to what the problem is :-) Commented Apr 19, 2013 at 11:29
  • 1
    Exactly - the executable loader still needs to find the dependent shared libraries, which it does through LD_LIBRARY_PATH. See kalblogs.blogspot.co.uk/2009/01/java.html Commented Apr 19, 2013 at 11:30

2 Answers 2

5

See http://kalblogs.blogspot.co.uk/2009/01/java.html:

java.library.path only works to resolve the immediate native library that you are loading in your code.

If this immediate library depends on other libraries (either within the same path as defined by java.library.path, or in a different location), these other libraries are loaded through the OS's standard mechanisms. In this case, it is also necessary to setup LD_LIBRARY_PATH accordingly.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use 'LD_LIBRARY_PATH' variable.

LD_LIBRARY_PATH: native code libraries (on Linux, in addition to the value of this variable, the lookup path typically contains /usr/local/lib, /usr/lib, /lib and a few others). The name LD comes from dynamic loader, the system component that loads libraries into dynamically linked executables.

EDIT:

Check this link : http://www.chilkatsoft.com/java-loadLibrary-Linux.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.