问题描述
我正在尝试加载本机库,因此会加载原始dll.但是在另一台运行XP 32位的计算机上,它可以正常工作.在Win7 64位系统上执行时,将无法加载.在xp机器上,dll文件可能与类文件位于同一目录中,但是为了不出现不满意的链接错误,我不得不将文件复制到system32文件夹中.然后,它给出了一个错误,指出无法在64位进程上加载32位dll.我下载了32位jdk,并在项目中设置了jdk以加载32位jdk.完成此操作后,我再次遇到不满意的链接错误,并且文件仍在system32中以及类文件旁边.对于使用64位jdk时为什么会在32位jdk中找不到该库的原因,我感到困惑.
I am attempting to load a native library which accordingly loads an original dll. However on another computer running XP 32bit, it works fine. When executed on a win7 64 bit system it would fail to load. On the xp machine, the dll files could be in same directory as class files, however in order to not get a unsatisfied link error, i had to copy the files into the system32 folder. Then it gave an error stating that a 32bit dll cannot be loaded on a 64 bit process. I downloaded the 32 bit jdk and set the jdk in the project to load the 32 bit jdk. When that was complete i again got an Unsatisfied link error, and the files are still in system32 as well as next to the class files. I am confused as to why it would find the library when using 64 bit jdk and will not in 32 bit jdk.
...
static {
System.loadLibrary("K8055jni");
}
Exception in thread "main" java.lang.UnsatisfiedLinkError: no K8055jni in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at K8055jni.<clinit>(K8055jni.java:50)
at Test.main(Test.java:4)
我如何获取32位jdk来定位相同的文件?
How do i get the 32 bit jdk to locate the same files?
推荐答案
如果我正确理解了您的问题,那么您可以尝试以下任何一种方法:
IF I understand your question and problem correctly, then you might try either of:
-
Windows 7将您的32位DLL放入\ Windows \ SysWOW64而不是\ Windows \ System32.奇怪的是,在Win 7下,System32仅适用于64位二进制文件.参见此和此以获取详细信息.
更好的是,将二进制文件放置在应用程序文件夹中,然后在java命令行上指定:
Better still, place your binary files in an application folder, and specify on the java command line:
-Djava.library.path=<path-to-dll-lib>
这篇关于从64位jdk切换到32位后,Java loadLibrary()无法找到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!