【发布时间】:2015-11-16 12:34:16
【问题描述】:
我正在编写一个需要使用 .dll 文件的程序。当我的程序启动时,会执行以下代码:
public static void main(String[] args)
{
String dLLURL = "C:/Program Files (x86)/Location of DLL";
System.setProperty("jna.library.path", dLLURL);
System.setProperty("jna.debug_load", "true");
System.setProperty("jna.debug_load.jna", "true");
Application.launch(args);
}
然后我执行
DllInterface dllinterface = (DllInterface) Native.loadLibrary( "dllName.dll", DllInterface.class);
...加载正确的 dll 并允许我使用它。 JNA 输出以下 (这次使用 DLL 的实际名称/路径):
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@e2f2a for /com/sun/jna/win32-x86/jnidispatch.dll
Found library resource at jar:file:/C:/Users/bengs_000/Downloads/jna.jar!/com/sun/jna/win32-x86/jnidispatch.dll
Trying C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna2314341730536889248.dll
Found jnidispatch at C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna2314341730536889248.dll
Looking for library 'RailDriver.dll'
Adding paths from jna.library.path: C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Found library 'RailDriver.dll' at C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
这就是我在 Eclipse IDE 中运行程序时发生的情况。效果很好!
但是,当我将程序作为 .jar 构建/运行时,应用程序说找不到 DLL(尽管在正确的位置查找)并返回以下消息:
Trying (via loadLibrary) jnidispatch
Looking in classpath from java.net.URLClassLoader@677327b6 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:rsrc:jna.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Trying C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna8530559464473818762.dll
Found jnidispatch at C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna8530559464473818762.dll
Looking for library 'RailDriver.dll'
Adding paths from jna.library.path: C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Adding system paths: []
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Looking for lib- prefix
Trying libRailDriver.dll
Looking in classpath from java.net.URLClassLoader@677327b6 for RailDriver.dll
There was an error finding your raildriver.dll file
如您所见,查找 .dll 文件的路径完全相同,但它在 Eclipse 中工作,而不是作为已编译的 .jar 文件!
您能帮我找出问题吗?需要注意的一点是 .dll 文件存储在 Program Files 的 32 位部分中,而我的计算机是 64 位的。我正在使用 Java 32bit 在 Eclipse 中编译和运行程序。当然它应该用 Java 32bit 构建 .jar 对吗?
【问题讨论】:
-
我想我需要以某种方式强制我的应用程序以 32 位模式执行(从 .jar),因为 DLL 是 32 位我的电脑是 64 位,但它在 Eclipse 中以 32 位运行。
标签: eclipse dll build jna 32-bit