简体   繁体   English

在资源路径中找不到本机库

[英]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.

相关问题 UnsatisfiedLinkError - 无法加载库 - 在资源路径中找不到本机库 - UnsatisfiedLinkError - Unable to load library - Native library not found in resource path 尝试在Mac OS X上加载JNA库时出现“无法加载库:在资源路径中找不到JNA本机支持” - “Unable to load library: JNA native support not found in resource path” on trying to load JNA library on Mac OS X 在资源路径中找不到本机库(com / sun / jna / android-aarch64 / libjnidispatch.so) - Native library (com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource path 在资源路径中找不到本机库(linux-x86-64 / libtesseract.so) - Native library (linux-x86-64/libtesseract.so) not found in resource path 在Java路径上找不到Tomcat本机库 - Tomcat native library not found on java path UnsatisfiedLinkError:在资源路径 (.) 中找不到本机库 (com/sun/jna/android-x86-64/libjnidispatch.so) - UnsatisfiedLinkError: Native library (com/sun/jna/android-x86-64/libjnidispatch.so) not found in resource path (.) 使用 gluonfx 编译为本机后,在资源路径中找不到 jnidispatch.dll - jnidispatch.dll not found in resource path after compile to native with gluonfx 找不到合适的本地库。 native.libpath。* vs java.library.path - No suitable native library found. native.libpath.* vs java.library.path 设置本机库路径 - Setting native library path 未找到 Java 本机文件,当本机文件明确位于 java.library.path 中时 - Java native file not found, when native file is clearly in java.library.path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM