问题
I have created a Java app which loads one Windows DLL from the static initialization block. The code snippet is given below:
// MyTestJava class starts
class MyTestJava
{
static
{
System.loadLibrary("MyLib");
}
} // MyTestJava class def ends here
I heard that for kinds of library initializations performed from static block, JVM should search in java.library.path
. So I set library path for JVM as follows and put MyLib.dll
under c:\Libs
folder.
options[1].optionString = "-Djava.library.path=C:\\Libs";
Unfortunately I'm getting a pesky Unsatisfied Link Error in my Java app.
回答1:
Not clear what options[1].optionString = "-Djava.library.path=C:\\Libs";
means. You should pass java.library.path as a java arg
java -Djava.library.path=C:\Libs MainClass
回答2:
First call getEnv and check if "java.library.path" actually refers to your library. Else You can try giving absolute path of file by using
static
{
System.load("C:\\Libs");
}
来源:https://stackoverflow.com/questions/16728586/system-loadlibrary-returns-exception-from-static-block