jna加载库
我在使用 jna 加载 dll 时遇到问题。虽然我可以在 Eclipse 中调试代码,但当我将其导出并作为 jar 文件运行时,出现异常:
java.lang.UnsatisfiedLinkError: 无法加载库 'SiUSBXp'
任何想法为什么它在运行时找不到我的 dll作为 jar 文件?
谢谢!!!!
public interface SiUSBXp extends StdCallLibrary {
byte SI_GetNumDevices(IntByReference numdevices);
byte SI_GetProductString( int deviceNum, byte[] productString, int options );
byte SI_Open(IntByReference numdevices);
}
static SiUSBXp INSTANCE;
public static void main(String[] args) {
System.setProperty("jna.library.path","SiUSBXp.dll");
HashMap<String, StdCallFunctionMapper> optionMap = new HashMap<String, StdCallFunctionMapper>();
StdCallFunctionMapper myMapper = new StdCallFunctionMapper();
optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper);
INSTANCE = (SiUSBXp) Native.loadLibrary("SiUSBXp", SiUSBXp.class, optionMap);
}
------------------ 编辑 ----------------------
dll 位于与该罐子是
------------------ 编辑 2 ---------------------
我刚刚尝试过在 Windows XP 中运行它并且它可以工作..但它不能在 Windows 7(64 位)中运行
------------------ 编辑 3 --------- ------------ 我已经解决了问题...这是由于安装了java版本...我将它们全部删除,然后只安装了x86版本的java...之后它完美运行
i'm having a problem on loading a dll with jna. While i can debug the code within eclipse, i get an Exception when i export and run it as a jar file:
java.lang.UnsatisfiedLinkError: unable to load library 'SiUSBXp'
Any ideas why it does not find my dll when i run it as a jar-file?
Thanks!!!!
public interface SiUSBXp extends StdCallLibrary {
byte SI_GetNumDevices(IntByReference numdevices);
byte SI_GetProductString( int deviceNum, byte[] productString, int options );
byte SI_Open(IntByReference numdevices);
}
static SiUSBXp INSTANCE;
public static void main(String[] args) {
System.setProperty("jna.library.path","SiUSBXp.dll");
HashMap<String, StdCallFunctionMapper> optionMap = new HashMap<String, StdCallFunctionMapper>();
StdCallFunctionMapper myMapper = new StdCallFunctionMapper();
optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper);
INSTANCE = (SiUSBXp) Native.loadLibrary("SiUSBXp", SiUSBXp.class, optionMap);
}
------------------ EDIT ----------------------
The dll is located in the same folder as the jar is
------------------ EDIT 2 ---------------------
I've just tried to run it within windows xp and it works .. but it does not within windows 7 (64 bit)
------------------ EDIT 3 ---------------------
I've solved the problem ... It was due to the java versions installed ... I removed them all, and then only installed the x86 version of java ... after that it worked perfectly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将DLL放入“当前文件夹”或系统变量PATH中,或使用
-Djna.library.path=(dll的路径)
作为VM开关而不是硬编码。Put the DLL into the "Current Folder" or system variable PATH, or use
-Djna.library.path=(path to the dll)
as VM switch instead of hard-coding.