dolaameng
dolaameng

Reputation: 1437

How to programmatically set the loading path of dynamic libraries in java?

System.setProperty("java.library.path", "pathToLibs");

doesn't work because it seems either "java.library.path" is read only or JVM just ignores the property.

I know it can be done by setting PATH(in windows), LD_LIBRARY_PATH(in POSIX) or just use the command java -Djava.library.path=your_path.

But is there a programming way of doing this?

Upvotes: 1

Views: 952

Answers (1)

jarnbjo
jarnbjo

Reputation: 34313

java.library.path is evaluated when the VM starts, so changing it later does not have any effect on loading native libraries. You can however use System.load(String filename); to specify the complete path to the native library you want to load, perhaps together with System.mapLibraryName(String) to add the platform specific file ending (e.g. .dll or .so).

Upvotes: 3

Related Questions