[英]native library not found in resource path
My application loads a native library (idcomm25.dll file). 我的应用程序加载了一个本机库(idcomm25.dll文件)。 If I start the application from command prompt with "java -jar myapplication.jar" command, or double clicking on myapplication.jar from explorer, all is fine. 如果我使用“ java -jar myapplication.jar”命令从命令提示符启动应用程序,或者双击资源管理器中的myapplication.jar,一切正常。 If I start the application via a .bat (even with 'run as administrator') that contains the same command as above, when the program tries to use the library, I get the error: 如果我通过包含与上述相同命令的.bat(即使使用“以管理员身份运行”)启动应用程序,则当程序尝试使用该库时,会出现错误消息:
Exception in thread ... java.lang.UnsatisfiedLinkError: Unable to load library
'idcomm25': Native library (win32-x86-64/idcomm25.dll) not found in resource
path ([myapplication.jar])
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
...
What am I missing? 我想念什么?
It would seem that you have both 64-bit and 32-bit JRE's installed. 似乎您已经安装了64位和32位JRE。
When you run directly from Command Prompt, or double-click the Jar file, you run the 64-bit JRE, and the idcomm25.dll
from the win32-x86-64
(64-bit) folder will load ok. 直接从命令提示符运行或双击Jar文件时,运行64位JRE, win32-x86-64
(64位)文件夹中的idcomm25.dll
将正常加载。
But, a .bat
file changes your path to 32-bit, and you end up running the 32-bit JRE, which cannot load the 64-bit .dll
file. 但是, .bat
文件会将您的路径更改为32位,最终您将运行32位JRE,该JRE无法加载64位.dll
文件。
You have choices: 您可以选择:
Qualify path to java
in the .bat
file to explicitly run the java.exe
from a 64-bit Java installation. 在.bat
文件中限定java
路径,以从64位Java安装中显式运行java.exe
。
Add the folder for 64-bit Java to beginning of the PATH. 将64位Java文件夹添加到PATH的开头。
This is my personal preference, so I'm in full control of which Java installation is used (I have more than 10 different JDK versions on my machine, for backward compatibility testing) . 这是我的个人喜好,因此我可以完全控制使用哪种Java安装(我的机器上有十多个不同的JDK版本,用于向后兼容性测试) 。
Uninstall 32-bit Java JRE (unconfirmed if this works) . 卸载32位Java JRE (如果可以,请确认) 。
Change code that calls loadLibrary
to load 32-bit version, eg from a win32-x86-32
folder, if running in 32-bit JVM. 如果在32位JVM中运行,则更改调用loadLibrary
代码以加载32位版本,例如从win32-x86-32
文件夹加载。 See " How can I tell if I'm running in 64-bit JVM or 32-bit JVM ". 请参阅“ 如何确定我是在64位JVM还是32位JVM中运行 ”。
See also: Trying to use DLL from Java (JNA). 另请参阅: 尝试使用Java(JNA)中的DLL。 Unable to load library exception 无法加载库异常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.