Setting java.library.path programatically

A

Aaron Fude

Hi,

Is there a way to modify java.library.path in the code?

I try the following in Windows

System.setProperty("java.library.path", "C:\\My\\Library\\Path;" +
System.getProperty("java.library.path"));
System.loadLibrary("MyLibrary");

....but it can't find it. (Everything works when I stick MyLibrary.dll
physically in one of the directories in the original path.)

Should what I'm trying to do work in principle? Thanks!

Aaron Fude
 
G

Gordon Beaton

Is there a way to modify java.library.path in the code?

I try the following in Windows

System.setProperty("java.library.path", "C:\\My\\Library\\Path;" +
System.getProperty("java.library.path"));
System.loadLibrary("MyLibrary");

...but it can't find it. (Everything works when I stick
MyLibrary.dll physically in one of the directories in the original
path.)

Should what I'm trying to do work in principle? Thanks!

No.

AFAIK, Java doesn't actually search for the shared library. Like many
of the system properties, the value in java.library.path is just
"f.y.i." and changing it doesn't actually change the behaviour of the
JVM.

On Unix, the dynamic linker (not the JVM!) searches for shared
libraries using a preconfigured path as well as the directories in the
user's LD_LIBRARY_PATH setting. On Windows, DLLs are loaded from the
PATH (although I don't know who does this search).

If you want to load a library from a specific location, you can use
System.load() instead (at the cost of some platform independence).

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top