无法从netbeans加载jna的个人dll

时间:2014-01-31 17:15:53

标签: java dll jna

我正在使用netbeans 7.4 / jdk 1.7u51

我从官方网站4.0.0版下载了JNA的jar。

我有一个内部开发的DLL,其接口是普通的C,它与ctypes中的python非常吻合。这个dll是在发布时使用visual 2010编译的,其运行时在路径中。

D:\fl006\Downloads>dir D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
 Directory of D:\deploy\SpotLight\spotlight-1488

29.01.2014  11:13         1'690'112 PasanBusLibrary.dll

我尝试用java加载它:jna:

public interface CLibrary extends Library {
     (...snip...)
    void pasanIpcInitializeLibrary(String xClient, String xBusName, int xTimeout);
    void pasanIpcTerminateLibrary();
}

public static void main(String[] args) {
    NativeLibrary.addSearchPath("PasanBusLibrary","D:\\deploy\\SpotLight\\spotlight-1488");
    CLibrary Bus = (CLibrary) Native.loadLibrary("PasanBusLibrary",CLibrary.class);
(... snip ...)    

这基本上是书本标准dll加载,来自自定义位置。

激活jna debug时,我看到以下内容:

run:
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Looking for library 'PasanBusLibrary'
Adding paths from jna.library.path: null
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Adding system paths: []
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Looking for lib- prefix
Trying libPasanBusLibrary.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for PasanBusLibrary
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'PasanBusLibrary': Native library (win32-x86-64/PasanBusLibrary.dll) not found in resource path ([file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/jna-platform-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/build/classes/])
    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)
    at testwrapperbus.TestWrapperBus.main(TestWrapperBus.java:39)

它看起来通过我给出的位置看起来并以某种方式丢弃它。我尝试了不同的文件夹,我有相同的行为,没有明显的文件系统正确的问题(dll是来自所有用户的RW)

关于我所缺少的任何线索,我现在有点卡住......

修改

  • 如果我加载“msvcrt”这对cll printf
  • 很有用
  • 我的dll有一些依赖项,所有这些依赖项都托管在c:\windows\system32中(标准运行时,动态链接)

1 个答案:

答案 0 :(得分:1)

当我使用win64 JDK / JRE时,我的dll是win32编译。当然,在处理纯java时,我们并不在意,但加载本机库需要匹配。

我尝试在32位JRE7上从命令行运行并且它有效,所以我很确定在我的netbeans中为win32安装JDK或者以64位重新编译我的dll将解决问题。

感谢这个答案:Trying to use DLL from Java (JNA). Unable to load library exception让我走上了正义的道路