我想在Eclipse中调用.DLL方法。这里是我的代码:在Java中加载.DLL
class TestJNI1 {
public native void LireNoVersion();
public void a() {
System.loadLibrary("tttt.dll");
LireNoVersion();
}
}
public GlobalAction() {
this.setBackground(GlobalPreferences.PANEL_BACKGROUND_COLOR);
new TestJNI1().a();
}
的问题是,我对编译此错误:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: tttt.dll at java.lang.Runtime.load0(Unknown Source) at java.lang.System.load(Unknown Source)
我已经尝试过:
- 设置参数在Eclipse
- 在移动项目的根目录和System32文件夹
- 在本机库loca中添加了文件夹路径重刑在Eclipse
- 更改Windows中的%PATH%
- 给予的绝对路径作为参数
- 与 “tttt.dll”, “./tttt.dll” 和 “.tttt.dll” 尝试
- 呼叫与
System.loadLibrary(...)
和System.load(...)
UPDATE
我试图打印java.library.path
,并得到一个路径。我把DLL在这条道路,现在的错误消息较为混乱:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: D:\My\Exact\Path\tttt.dll: Can't find dependent libraries
这里是打印路径代码:
String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
while (parser.hasMoreTokens()) {
System.err.println(parser.nextToken());
}
如果你指定一个绝对路径到你的DLL,例如'C:/ tttt.dll',它会工作吗?你有没有尝试过以下所有的例子:https://www.chilkatsoft.com/java-loadLibrary-Windows.asp – Cyclonecode
当你指定一个绝对路径时,你会得到相同的错误信息**'C:/ tttt.dll'? – Cyclonecode
是的,我也试过 – Totem