5

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.

Steven Jeffries
  • 3,522
  • 2
  • 20
  • 35
  • 1
    I guess a look in the source [os_solaris.cpp](https://github.com/openjdk-mirror/jdk7u-hotspot/blob/master/src/os/solaris/vm/os_solaris.cpp#L743) / [os_windows.cpp](https://github.com/openjdk-mirror/jdk7u-hotspot/blob/master/src/os/windows/vm/os_windows.cpp#L194) will answer your questions. – SubOptimal Apr 30 '15 at 13:12
  • Possible duplicate of [Default Java library path?](https://stackoverflow.com/questions/20038789/default-java-library-path) – Étienne Miret Sep 25 '17 at 09:58
  • @EtienneMiret It's definitely very close to my question. However, my question isn't asking *what* it's set to, it's asking where these values are hard-coded at. It has been 2 years, and I doubt I'll get an answer on here, so if you think I should click the "solved my problem" button, I'll do that. – Steven Jeffries Sep 25 '17 at 10:07

2 Answers2

2

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

Thorgull
  • 21
  • 2
-2

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.

DesirePRG
  • 6,122
  • 15
  • 69
  • 114
  • 1
    Yes, I know how to set and check the values, my question is where these values come from, and if they are the same across different distros. – Steven Jeffries May 01 '15 at 03:40