[英]jna load library
i'm having a problem on loading a dll with jna. 我在用jna加载dll时遇到问题。 While i can debug the code within eclipse, i get an Exception when i export and run it as a jar file:
虽然我可以在eclipse中调试代码,但是在导出并将其作为jar文件运行时会出现异常:
java.lang.UnsatisfiedLinkError: unable to load library 'SiUSBXp' java.lang.UnsatisfiedLinkError:无法加载库“ SiUSBXp”
Any ideas why it does not find my dll when i run it as a jar-file? 有什么想法为什么当我将其作为jar文件运行时找不到我的dll?
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 dll位于与jar相同的文件夹中
------------------ EDIT 2 --------------------- ------------------编辑2 ---------------------
I've just tried to run it within windows xp and it works .. but it does not within windows 7 (64 bit) 我刚刚尝试在Windows XP中运行它,但是它可以工作..但是在Windows 7(64位)中却不能运行
------------------ 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 ------------------编辑3 ---------------------我已经解决了问题...这是由于安装了Java版本...我将它们全部删除,然后仅安装了x86版本的Java ...之后,它可以正常工作
将DLL放入“当前文件夹”或系统变量PATH中,或将-Djna.library.path=(path to the dll)
用作VM切换器,而不是硬编码。
I've had strange problems with jna 3.3.0 not finding libraries, try jna 3.2.7. 我遇到了jna 3.3.0找不到库的奇怪问题,请尝试jna 3.2.7。 Also, besides
jna.library.path
, it could help to set java.library.path
too. 另外,除了
jna.library.path
之外,它还可以帮助设置java.library.path
。 And I'm not sure if you should put library name in the path and not the folder the library is in. Try to set it to ".". 而且我不确定是否应该将库名放在路径中,而不要放在库所在的文件夹中。请尝试将其设置为“。”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.