在 Eclipse/PyDev Jython 项目中将 .dll 添加到 java.library.path
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11123274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add .dll to java.library.path in Eclipse/PyDev Jython project
提问by Robbie Rosati
I'm trying to use a compiled .jar Java library in my PyDev Jython project.
我正在尝试在我的 PyDev Jython 项目中使用编译的 .jar Java 库。
I successfully added the .jar to the PYTHONPATH and was able to begin coding with auto complete working.
我成功地将 .jar 添加到 PYTHONPATH 并且能够开始自动完成工作的编码。
The library requires a .dll extension as well, javaHeclib.dll
, so I added that to the External Libs section of my project.
该库也需要 .dll 扩展名javaHeclib.dll
,因此我将其添加到我项目的外部库部分。
I can import the library fine, but I get an error when I try to access any of its functions:
我可以很好地导入库,但是当我尝试访问它的任何函数时出现错误:
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: no javaHeclib in java.library.path
I added a VM argument to my Run Configuration, with no luck:
我在运行配置中添加了一个 VM 参数,但没有运气:
-Djava.library.path="Y:/path/to/javaHeclib.dll;${env_var:PATH}"
I can run the library from the command line just fine using the java.library.path
above.
我可以使用java.library.path
上面的命令从命令行运行库。
Experimenting in the PyDev Console, I noticed I can load the .dll extension with an absolute path, but not a relative one:
在 PyDev 控制台中进行实验时,我注意到我可以使用绝对路径加载 .dll 扩展名,但不能加载相对路径:
>>> import java.lang
>>> java.lang.System.load('Y:/path/to/javaHeclib.dll')
>>> java.lang.System.loadLibrary('javaHeclib')
Traceback (most recent call last):
File "<console>", line 1, in ?
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: no javaHeclib in java.library.path
Unfortunately, the library is using the the System.loadLibrary
call above, and I don't have access to its source.
不幸的是,该库正在使用System.loadLibrary
上面的调用,而我无权访问其源代码。
Why is javaHeclib.dll
not in my java.library.path
?
为什么javaHeclib.dll
不在我的java.library.path
?
EDIT
编辑
Setting the java.library.path
to the directory containing the dll didn't allow me to load it using System.loadLibrary
.
将 设置为java.library.path
包含 dll 的目录不允许我使用System.loadLibrary
.
-Djava.library.path="Y:/path/to/dll/;${env_var:PATH}"
(Using forward slashes didn't make a difference.) I also tried changing the default VM args in eclipse.ini
, with no luck:
(使用正斜杠没有区别。)我也尝试更改默认的 VM args in eclipse.ini
,但没有运气:
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
-Djava.library.path="Y:\path\to\dll\;${env_var:PATH}"
采纳答案by Robbie Rosati
I got this working.
我得到了这个工作。
For future reference:
备查:
Say the dll you need is in Y:\path\to\dlls\lib\
. Then set your Run Configuration's working directory to Y:\path\to\dlls\
and set your VM arguments to include -Djava.library.path=lib
.
假设您需要的 dll 在Y:\path\to\dlls\lib\
. 然后将您的运行配置的工作目录Y:\path\to\dlls\
设置为并将您的 VM 参数设置为 include -Djava.library.path=lib
。
That's it, it should now work. I don't know why specifying an absolute path in java.library.path
didn't work previously, but setting a working directory seems to have done it.
就是这样,它现在应该可以工作了。我不知道为什么在java.library.path
之前指定绝对路径不起作用,但设置工作目录似乎已经完成了。
Perhaps it's something peculiar to the specific library I'm using (or that Eclipse is running from a different drive than the library is on)...
也许这是我正在使用的特定库所特有的(或者 Eclipse 从与库所在的驱动器不同的驱动器上运行)......
回答by Wayne
I think the better way is:
我认为更好的方法是:
- Create a folder under the project, for example dll.
- Copy/paste all dll files into this folder.
- In project -> Properties -> Java Build Path -> Source, click and expand the source details.
- You will see Native library location, click/highlight it.
- Then click edit on the right, click workspace again. You can see the dll folder under the project.
- Select it and click OK, OK. You will see the dll is added in the Native library location.
- 在项目下创建一个文件夹,例如dll。
- 将所有 dll 文件复制/粘贴到此文件夹中。
- 在项目 -> 属性 -> Java 构建路径 -> 源中,单击并展开源详细信息。
- 您将看到本机库位置,单击/突出显示它。
- 然后点击右侧的编辑,再次点击工作区。可以看到项目下的dll文件夹。
- 选择它,然后单击“确定”、“确定”。您将看到 dll 添加到本机库位置。
That's it. You do not need to manually change anything in configuration.
就是这样。您无需手动更改配置中的任何内容。
回答by Jeya Venkatesh
I had similar issue but with Ghost Script dll. Even when followed placing the files in working directory and followed the instructions, it didn't work for me, refer the tag Ghost4J. java.lang.UnsatisfiedLinkError: Unable to load library 'gsdll64'and used the -Djna.library.path to get it worked.
我有类似的问题,但使用 Ghost Script dll。即使按照将文件放在工作目录中并按照说明进行操作,它对我也不起作用,请参阅标签 Ghost4J。java.lang.UnsatisfiedLinkError:无法加载库“gsdll64”并使用 -Djna.library.path 使其工作。