Reputation: 3572
I'm just wondering how, exactly, does Java go about deciding the default value for its java.library.path
property?
I am running a *buntu 14.04 64 bit, and it defaults to (the first two don't exist):
/usr/java/packages/lib/amd64
/usr/lib64
/lib64
/lib
/usr/lib
Searching through my environmental variables, I have found that nothing has these in it. Setting LD_LIBRARY_PATH
does prepend its contents to this list.
Given this information, I am assuming that this list is just explicitly set (hard-coded) into Java, but I can't find any documentation on it. Is my assumption correct? What are its default values for different OSs? Will these values change across distributions?
I'm asking for two reasons. 1) I'm just curious. 2) I want to know where I can put a library so that Java will always find it.
Upvotes: 6
Views: 10682
Reputation: 41
On my Debian system, if I check the value of java.library.path with the command
java -XshowSettings:properties
The java from the system package installed return the correct value :
/usr/java/packages/lib
/usr/lib/x86_64-linux-gnu/jni
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
/usr/lib/jni
/lib
/usr/lib
The java from the open-jdk I downloaded on openjdk site returns :
/usr/java/packages/lib
/usr/lib64
/lib64
/lib
/usr/lib
I found each returned value in the binary libjvm.so of the corresponding jdk/jvm
Upvotes: 4
Reputation: 6378
If you want to find the path which is set currently in your machine, run the following.
System.out.println(System.getProperty("java.library.path"));
you can explicitly set the path in your code as following
System.setProperty(“java.library.path”, “/path/to/library”);
through command line
java -Djava.library.path=<path>
Also I wouldn't call it an environment variable. It is a system property used by the jvm.
Upvotes: -2