Default Java library path?
Asked Answered
T

3

44

I understand that you can set the Java library path with an option (-Djava.library.path=/path/to/libs) before executing the program, but is there a place on the system where Java looks if you don't set it manually?

Trivandrum answered 18/11, 2013 at 1:53 Comment(0)
C
49

Its default value depends on the operating system:

  • On Windows, it maps to PATH
  • On Linux, it maps to LD_LIBRARY_PATH
  • On OS X, it maps to DYLD_LIBRARY_PATH
Cristinecristiona answered 18/11, 2013 at 1:56 Comment(3)
Where does this infomation come from?Cetus
Good question, no idea.Cristinecristiona
The default value is set by a native method in System.java and I don't have time to dig further into it atm.Cristinecristiona
P
12

However, Matt Ball is not totally correct.

On my Linux box, my Java library path is

/usr/lib64/icedtea6/jre/lib/amd64/server:/usr/lib64/icedtea6/jre/lib/amd6ib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

While my LD_LIBRARY_PATH is /usr/local/lib64.

Preternatural answered 26/3, 2014 at 16:22 Comment(1)
Sun / Oracle changed the behavior between 1.6 and 1.7: blogs.oracle.com/darcy/entry/purging_ld_library_pathSpiritless
T
12

For Java 8, this differs based on OS. This is the behavior I observed:

  • Windows 10/Oracle JDK 8: java.library.path=%PATH%;.
  • macOS El Capitan/Oracle JDK 8: java.library.path=$JAVA_LIBRARY_PATH:~/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.. DYLD_LIBRARY_PATH and LD_LIBRARY_PATH variables are ignored. Moreover, both these variables are removed from the environment of Java applications.
  • Linux CentOS 7/Open JDK 8: java.library.path=$LD_LIBRARY_PATH:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Trinitroglycerin answered 27/2, 2018 at 21:13 Comment(1)
Apparently JAVA_LIBRARY_PATH still works with El Captain and jdk 8, or at least with the recent 1.8.0_162-b12 buildTrinary

© 2022 - 2024 — McMap. All rights reserved.