将 DLL 导入 Eclipse Java 项目
为了将 DLL 导入 Eclipse Java 项目,我检查了“java.library.path”
String path = System.getProperty("java.library.path");
System.out.println(path);
path
值之一是否等于 C:/Windows/System32
。因此我将myAPI.dll
保存在C:/Windows/System32
中。然后我调用 System.loadLibrary:
System.loadLibrary("myAPI.dll");
并收到错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: myAPI.dll
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
顺便说一句,我尝试将 DLL 文件放在 path
中提到的不同其他目录中。但每次我都收到相同的错误消息。如何解决这个问题呢?
To import DLL into Eclipse Java project, I checked the "java.library.path"
String path = System.getProperty("java.library.path");
System.out.println(path);
One of the path
values was equal to C:/Windows/System32
. Therefore I saved myAPI.dll
in C:/Windows/System32
. Then I called System.loadLibrary
:
System.loadLibrary("myAPI.dll");
And got the error message:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: myAPI.dll
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
BTW, I tried to put my DLL file in different other directories that was mentioned in path
. But each time I got the same error message. How to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要将“.dll”放在库的末尾。这是 Windows 特定的扩展,您的呼叫将在具有其他扩展的其他系统上运行,因此打开该扩展是不正确的。只需加载“myAPI”,如果名称正确并且其他内容如广告所述,它将起作用。
Don't put ".dll" at the end of your library. That is a Windows-specific extension, and your call will work on other systems with other extensions, so putting the extension on is incorrect. Just load "myAPI" and, if that's the right names and other things are as advertised, it will work.
一种选择是尝试将该 dll 保留在 eclipse 系统库中使用的 /jre/bin 中,并能够在运行时配置 dll 文件,通过将 dll 放入 /jre/bin
这是我能找到的最简单的方法。这对我有用。希望能帮助你。:)
One option is to try keeping that dll in your /jre/bin used in eclipse system library and was able to configure dll files at runtime , by placing dll in /jre/bin
It is the simplest way i could find out. This work for me.Hopefully will help you.:)
如果 dll 位于您的项目文件夹中(例如项目的一部分),即:
并且您想要在 eclipse 中执行程序/单元测试,您可以配置运行程序的运行时环境。转到“Preferences/Java/Installed JREs”,选择所需的 JRE 或 JDK(注意:要加载 32 位 dll,您必须使用 32 位 JRE,尽管您的主机系统是 64 位系统),单击“编辑”。在“默认 VM 参数”框中输入
这会将 dll 文件夹“prod/bin”添加到系统路径前面(不用担心,这不是永久的,仅适用于所选 JRE 的环境)。
通过运行以下代码,您可以验证系统路径是否已更新并且可以加载 dll:
If the dll is in your project folder (e.g. part of your project), i.e.:
and you want to execute the program/unit test within eclipse you can configure the runtime environment which runs your program. Go to "Preferences/Java/Installed JREs", choose the desired JRE or JDK (note: for loading a 32bit dll you must use a 32bit JRE, although your host system is a 64bit system), click on "Edit". In the box "Default VM arguments" you enter
This adds your dll folder "prod/bin" in front of the system path (don't bother, it's not permanently, only for the environment of the chosen JRE).
By running following code you can verify that the system path was updated and the dll can be loaded: