问题描述
我创建了一个 Java 应用程序,它从静态初始化块加载一个 Windows DLL.代码片段如下:
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
我听说对于从静态块执行的各种库初始化,JVM 应该在 java.library.path
中搜索.所以我为JVM设置库路径如下,并将MyLib.dll
放在c:\Libs
文件夹下.
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";
不幸的是,我在我的 Java 应用程序中遇到了令人讨厌的 Unsatisfied Link 错误.
Unfortunately I'm getting a pesky Unsatisfied Link Error in my Java app.
推荐答案
不清楚 options[1].optionString = "-Djava.library.path=C:\\Libs";
是什么意思.您应该将 java.library.path 作为 java arg 传递
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
这篇关于System.loadLibrary() 从静态块返回异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!