如何从.jar文件引用.dll [英] How to reference a .dll from a .jar file

查看:226
本文介绍了如何从.jar文件引用.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序在调用.dll的.jar中使用方法。这对我在我的机器上工作正常(当应用程序未打包或以.jar本身运行时),但是当application.jar在另一台计算机上运行且系统路径为外部.dll时,它将无法运行dll文件。

I have an application which uses methods in a .jar which calls a .dll. This works fine for me on my machine (when the app is unpackaged or run as a .jar itself) but when the application.jar is run on another machine, with the external .dll on the system path, it cannot run the dll file.

.dll是否必须位于特殊的地方?我以为可以在系统路径上找到它。

Does the .dll have to be located anywhere special? I has assumed that as it was on the system path that it would be found.

预先感谢

Dougie

推荐答案

java.library.path解决方案并不总是很好:在许多情况下,您无法更改JVM参数。更好的解决方案:

java.library.path solution isn't always good: there are many situations where you can't change JVM parameters. Better solutions:

1):将DLL与JAR放在同一目录中,不幸的是,这使得使用这样的JAR更加困难-现在JAR不仅仅是JAR,但有一个附带的DLL

1) already mentioned: put DLL in the same directory as JAR, unfortunately it makes usage of such a JAR harder - now the JAR isn't just a JAR, but has an accompanying DLL

2)将DLL作为普通资源放入JAR,在JAR启动过程中将该DLL提取到某个位置,例如$ TMP,然后如上所述使用System.load(new File(...))。然后,这个JAR只是一个JAR,这个JAR的用户甚至可能都不知道它使用了什么DLL

2) put the DLL into the JAR as a normal resource, during JAR startup extract this DLL somewhere to e.g. $TMP, and then use System.load(new File(...)) as above. Then this JAR is just a JAR, users of this JAR may even don't know that it uses any DLLs

您还可以使用Maven NAR插件,该插件功能非常强大如果您使用Maven构建。参见 http://duns.github.com/maven-nar-plugin/

You can also use Maven NAR plugin, which is quite powerful if you're usin Maven for builds. See http://duns.github.com/maven-nar-plugin/

这篇关于如何从.jar文件引用.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆