在Netbeans中加载DLL

时间:2013-04-20 15:14:39

标签: java dll java-native-interface jna unsatisfiedlinkerror

我正在尝试在Netbeans 7.0.1中加载DLL文件,

代码是

dll = (RRHFEK02DLL)Native.loadLibrary("RRHFEK02DLL.dll", RRHFEK02DLL.class);
utility = (Utilities)Native.loadLibrary("Utilities.dll",Utilities.class);
wraper =(RRHFEK02Wrapper)Native.loadLibrary("RRHFEK02Wrapper.dll", RRHFEK02Wrapper.class);

第一行没有错误,这行是在提供者的演示中,现在我想要另外两个dll加载,我已经添加了下两行并且还在库中添加了dll文件,但是我收到了错误

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
Unable to load library 'Utilities.dll': The specified module could not
be found.
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:393)
    at com.sun.jna.Native.loadLibrary(Native.java:378)
    at rrhfek02.RRHFEK02View.<init>(RRHFEK02View.java:87)
    at rrhfek02.RRHFEK02App.startup(RRHFEK02App.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

我已经通过相同/相关的问题传出,但没有得到解决方案。 所以,如果有人提出建议,请提供给我。

2 个答案:

答案 0 :(得分:1)

您需要插入.dll扩展名(如果扩展程序为.framework,则在Mac上不需要。在我的系统上,使用我的netbeans项目文件夹结构:

  

LIB

+ src
+ EDSDK
      -dll
          -EDSDK
      -headers
+Other Files

做:

this.EDSDK = (EdSdkLibrary) Native.loadLibrary("EDSDK/dll/EDSDK.dll", EdSdkLibrary.class

有效加载它。在加载之前,您可以尝试new File("RRHFEK02DLL.dll").exists()返回的内容。如果false,那么您的路径是错误的。如果是true,那么问题就是

答案 1 :(得分:0)

删除Java中的".dll"。那就是:

dll = (RRHFEK02DLL) Native.loadLibrary("RRHFEK02DLL", RRHFEK02DLL.class);
utility = (Utilities) Native.loadLibrary("Utilities", Utilities.class);
wraper = (RRHFEK02Wrapper) Native.loadLibrary("RRHFEK02Wrapper", RRHFEK02Wrapper.class);

请勿修改实际的DLL文件名称!