Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将DLL导入Eclipse Java项目_Java_Eclipse_Dll - Fatal编程技术网

将DLL导入Eclipse Java项目

将DLL导入Eclipse Java项目,java,eclipse,dll,Java,Eclipse,Dll,为了将DLL导入EclipseJava项目,我检查了“Java.library.path” 其中一个path值等于C:/Windows/System32。因此,我在C:/Windows/System32中保存了myAPI.dll。然后我调用了System.loadLibrary: System.loadLibrary("myAPI.dll"); 并收到错误消息: Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkEr

为了将DLL导入EclipseJava项目,我检查了“Java.library.path”

其中一个
path
值等于
C:/Windows/System32
。因此,我在
C:/Windows/System32
中保存了
myAPI.dll
。然后我调用了
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
中提到的其他不同目录中。但每次我都收到同样的错误信息。如何解决这个问题?

不要将“.dll”放在库的末尾。这是一个特定于Windows的分机,您的呼叫将在具有其他分机的其他系统上工作,因此使用分机是不正确的。只要加载“myAPI”,如果名称正确,并且其他内容如广告所示,它就会工作。

一个选项是尝试将该dll保存在eclipse系统库中使用的/jre/bin中,并且能够在运行时通过将dll放置在/jre/bin中来配置dll文件


这是我能找到的最简单的方法。这是我的工作。希望能对您有所帮助。:

如果dll位于您的项目文件夹中(例如,项目的一部分),即:

如果要在eclipse中执行程序/单元测试,可以配置运行程序的运行时环境。转到“Preferences/Java/Installed JRE”,选择所需的JRE或JDK(注意:要加载32位dll,您必须使用32位JRE,尽管您的主机系统是64位系统),请单击“编辑”。在“默认VM参数”框中输入

-Djava.library.path="./prod/bin;${env_var:PATH}"
这会将dll文件夹“prod/bin”添加到系统路径前面(不用麻烦,它不是永久性的,只适用于所选JRE的环境)

通过运行以下代码,您可以验证系统路径已更新,并且可以加载dll:

        String path = System.getProperty("java.library.path");
        System.out.println(path);
        System.loadLibrary("myAPI");

我找到了解决方案:System.loadLibrary(“myAPI”);而不是System.loadLibrary(“myAPI.dll”);
-Djava.library.path="./prod/bin;${env_var:PATH}"
        String path = System.getProperty("java.library.path");
        System.out.println(path);
        System.loadLibrary("myAPI");