Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to setting java.library.path?

I have a Java program making some JNI calls to a native library ("mylib.so"). Whenever I want to run this program, from the command line, I must set java.library.path to the location of my library as such:

java -Djava.library.path=/var/natives/ -classpath MyPackage.jar MyPackage.MyClass arg1 arg2

I'm wondering if there are any alternatives so I do not have to set it with the -D option everytime I run my program.

I have tried adding /var/natives/ to my $PATH variable, but it still complains that it cannot find the library if I do not explicitly set it with -D.

Do I have any other options?

like image 317
Petey B Avatar asked Oct 24 '22 10:10

Petey B


2 Answers

Just put the entire command in a .sh file to save yourself from repeating it everytime.

like image 67
BalusC Avatar answered Oct 27 '22 10:10

BalusC


Instead of using System.loadLibrary("mylib"), use System.load("/var/natives/mylib.so").

Or, you could define a custom class loader for the class and override the ClassLoader.findLibrary(String) method.

like image 45
Kevin K Avatar answered Oct 27 '22 09:10

Kevin K