简体   繁体   中英

native library not found in resource path

My application loads a native library (idcomm25.dll file). 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. 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:

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.

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.

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.

You have choices:

  • Qualify path to java in the .bat file to explicitly run the java.exe from a 64-bit Java installation.

  • Add the folder for 64-bit Java to beginning of the 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) .

  • Uninstall 32-bit Java JRE (unconfirmed if this works) .

  • Change code that calls loadLibrary to load 32-bit version, eg from a win32-x86-32 folder, if running in 32-bit JVM. See " How can I tell if I'm running in 64-bit JVM or 32-bit JVM ".

See also: Trying to use DLL from Java (JNA). Unable to load library exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM