Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting java.library.path 1

Status
Not open for further replies.

tjmcc18

Programmer
Jul 8, 2003
4
US
Hi,

I am attempting to load a library in Linux using a command like:

System.loadLibrary("libName");

It appears that in order for Java to find the library when I run the program, I have to somehow set a path where the library can be found. Setting LD_LIBRARY_PATH works, but I would like to avoid this. I have found that when I set java.library.path on the command line like this, it works:

java -Djava.library.path=/root/libraryDir test

But for some reason when I try to set the path inside the code it doesn't work. I continue to get "java.lang.UnsatisfiedLinkError". I have even printed out the path inside the error handling and it indeed has the path I added, but for some reason it still doesn't find the library. I am using the following commands:

String path = System.getProperty("java.library.path");

System.setProperty("java.library.path",path + ":/root/libraryDir:");

If anyone knows how to correctly set the java.library.path inside the code, I would appreciate it. Thanks.
 
System.setProperty("java.library.path","/root/libraryDir:");


-pete
 
Simply removing the ":" doesn't seem to do much good. It seems that no matter what I set the path to in the code, the default path is always used instead.

Any other ideas?
 
I figured out this one myself. The simple answer is, there is no way to set the java.library.path dynamically. The JVM caches the path when it loads, and uses that path during execution. Even though you can change the value of the path, the JVM doesn't check it anymore. The only options are to use System.load() and set give it the absolute path, or to specify the path on the command line. Hope that helps anyone else with similar problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top