简体   繁体   English

Windows,JNA:无法加载本机库-UnsatisfiedLinkError

[英]Windows, JNA: Cannot load native library - UnsatisfiedLinkError

I am using Java 7 on Windows 7 and am trying to use Java JNA (Java Native Access) (4.2.2) [ link: https://github.com/java-native-access/jna ] to provide access to a C language native library . 我在Windows 7上使用Java 7 ,并尝试使用Java JNA (Java本机访问)(4.2.2)[链接: https : //github.com/java-native-access/jna ]提供对C语言的访问语言本机库 I have done this on a Linux system and have no problems finding and loading the library. 我已经在Linux系统上完成了此任务,并且找到并加载库没有问题。

I am using the suggested technique of setting the system property jna.library.path to the path where the library is located. 我正在使用将系统属性jna.library.path设置为库所在路径的建议技术。 As mentioned above, this works on Linux, but on Windows I cannot get it to find and load the library. 如上所述,这在Linux上有效,但是在Windows上我无法找到并加载该库。

On the Windows platform, the library comes in both 32 and 64 bit variants (I'm trying to use the 32-bit), with both .lib and .dll files. 在Windows平台上,该库具有32位和64位变体(我正在尝试使用32位),同时具有.lib和.dll文件。

I also set the system properties jna.debug_load and jna.debug_load.jna to true as suggested to watch how JNA does its thing. 我还按照建议将系统属性jna.debug_loadjna.debug_load.jna设置true ,以观察JNA的工作方式。

I have tried the following to no avail: 我尝试了以下无济于事:

  • System.setProperty("jna.library.path", "C:\\Program Files (x86)\\VMware\\VMware VIX"); System.setProperty(“ jna.library.path”,“ C:\\ Program Files(x86)\\ VMware \\ VMware VIX”); ( Windows style path ) Windows样式路径
  • System.setProperty("jna.library.path", "C:/Program Files (x86)/VMware/VMware VIX"); System.setProperty(“ jna.library.path”,“ C:/程序文件(x86)/ VMware / VMware VIX”); ( UNIX style path ) UNIX样式路径
  • I placed the library in a path that has no spaces in it. 我将库放在没有空格的路径中。
  • I added the library name on the path (with and without file extension). 我在路径上添加了库名称(带和不带文件扩展名)。 Eg "C:\\Program Files (x86)\\VMware\\VMware VIX\\VixAllProductsDyn". 例如,“ C:\\ Program Files(x86)\\ VMware \\ VMware VIX \\ VixAllProductsDyn”。 (VixAllProductsDyn.dll) (VixAllProductsDyn.dll)

When I make an attempt, I can see the debug information on the Java console. 尝试时,可以在Java控制台上看到调试信息。 Oddly, it tries the exact path to where the library file sits - and yet does not find it . 奇怪的是,它尝试查找库文件所在的确切路径,但找不到它

If anyone has run into this and knows anything about solving the problem, it would be much appreciated. 如果有人遇到了这个问题并且对解决问题一无所知,将不胜感激。

Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@1a1a7aa4 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna/4.2.2/jna-4.2.2.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Trying C:\Users\jo24447\AppData\Local\Temp\jna--734724592\jna8544680981267090708.dll
Found jnidispatch at C:\Users\jo24447\AppData\Local\Temp\jna--734724592\jna8544680981267090708.dll
Looking for library 'VixAllProductsDyn'
Adding paths from jna.library.path: C:\Program Files (x86)\VMware\VMware VIX
Trying C:\Program Files (x86)\VMware\VMware VIX\VixAllProductsDyn.dll
Adding system paths: []
Trying C:\Program Files (x86)\VMware\VMware VIX\VixAllProductsDyn.dll
Looking for lib- prefix
Trying libVixAllProductsDyn.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@1a1a7aa4 for VixAllProductsDyn
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'VixAllProductsDyn': Native library (win32-x86-64/VixAllProductsDyn.dll) not found in resource path ([file:/C:/Users/jo24447/luna_workspace/VMUtil/vm-util/target/classes/, file:/C:/Users/jo24447/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar, file:/C:/Users/jo24447/.m2/repository/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar, file:/C:/Users/jo24447/.m2/repository/org/slf4j/slf4j-log4j12/1.7.2/slf4j-log4j12-1.7.2.jar, file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna/4.2.2/jna-4.2.2.jar, file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna-platform/4.2.2/jna-platform-4.2.2.jar])
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:277)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:342)
    at edu.mit.ll.oms.security.vm.VIXLibrary.<clinit>(VIXLibrary.java:24)
    at edu.mit.ll.oms.security.vm.test.QuickTest.main(QuickTest.java:16)

(1) Try the following: (1)尝试以下方法:

  1. Put both windows (64/32Bit) dlls (and .so's if you wish) into a zip file and rename the file to .jar afterwards. 将两个Windows(64 / 32Bit)dll(如果需要,也可以添加.so)放入一个zip文件中,然后将该文件重命名为.jar。
  2. Add that file to your application classpath. 将该文件添加到您的应用程序类路径。
  3. Now if your dll is named "VixAllProductsDyn.dll" then call loadLibrary like this: Native.loadLibrary("VixAllProductsDyn","VixAllProductsDyn.class"); 现在,如果您的dll名为“ VixAllProductsDyn.dll”,则按如下方式调用loadLibrary:Native.loadLibrary(“ VixAllProductsDyn”,“ VixAllProductsDyn.class”);

(2) Secondly did you try to set the path like this: java -Djava.library.path=c:\\yourLocation VixAllProductsDyn (2)其次,您是否尝试像这样设置路径:java -Djava.library.path = c:\\ yourLocation VixAllProductsDyn

(3) If you have an applet/webstart application you can specify the native library location with the native lib attribute. (3)如果您有applet / webstart应用程序,则可以使用native lib属性指定本地库位置。

(4) Other than that you may answer the following questions: What architecture (32/64Bit) does your windows system have? (4)除此之外,您可能会回答以下问题:Windows系统具有什么体系结构(32 / 64Bit)? What architecture (32/64Bit) does your java have? 您的Java有什么架构(32 / 64Bit)? What version of the dll do you try to run in which case? 在这种情况下,您尝试运行哪个版本的dll?

Maybe you try an invalid combination of system architecture / JVM and library version... 也许您尝试使用无效的系统架构/ JVM和库版本组合...

Update: 更新:

Can you share your code? 您可以共享您的代码吗? It should look something like this: 它看起来应该像这样:

VixAllProductsDyn lib = (VixAllProductsDyn) Native.loadLibrary("VixAllProductsDyn", VixAllProductsDyn.class);

The VixAllProductsDyn.java is an interface containing all methods you want to use: VixAllProductsDyn.java是包含您要使用的所有方法的接口:

public interface VixAllProductsDyn extends Library {

    public abstract NativeLong OneOfTheMethodsYouWantToCall();
    ...
}

Are you sure that you included all the necessary *.dlls and *.libs etc. which are needed? 您确定已包含所有必需的* .dll和* .libs等吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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