//最直接的方式是将umsDevTool_sp30.dll放在System32下面,Mapper接口继承Library Mapper instance3 = (Mapper) Native.loadLibrary("umsDevTool_sp30", Mapper.class);
使用JNA时加载动态库,报错如下:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library ‘umsDevTool_sp30‘: Native library (win32-x86-64/umsDevTool_sp30.dll) not found in resource path ([file:/D:/workspaces_for_java/JnaDll/bin/, file:/D:/workspaces_for_java/JnaDll/lib/jna-4.1.0.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) at com.win32.Mapper.<clinit>(Mapper.java:21) at com.win32.Main.main(Main.java:8)
问题在于:动态库是32位的,而JDK是64位的,所以,如果要调用32位的JDK必须是32位的;相应地,如果动态库是64位的,必须使用64位JDK。
时间: 2024-11-10 20:26:06