简体   繁体   English

从64位jdk切换到32位后,Java loadLibrary()无法找到库

[英]Java loadLibrary() cannot locate library after switching from 64 bit jdk to 32 bit

I am attempting to load a native library which accordingly loads an original dll. 我正在尝试加载本机库,因此会加载原始dll。 However on another computer running XP 32bit, it works fine. 但是在另一台运行XP 32位的计算机上,它可以正常工作。 When executed on a win7 64 bit system it would fail to load. 在Win7 64位系统上执行时,将无法加载。 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. 在xp机器上,dll文件可能与类文件位于同一目录中,但是为了不出现不满意的链接错误,我不得不将文件复制到system32文件夹中。 Then it gave an error stating that a 32bit dll cannot be loaded on a 64 bit process. 然后它给出了一个错误,指出不能在64位进程上加载32位dll。 I downloaded the 32 bit jdk and set the jdk in the project to load the 32 bit jdk. 我下载了32位jdk,并在项目中设置了jdk以加载32位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. 完成该操作后,我再次遇到不满意的链接错误,并且文件仍在system32中以及类文件旁边。 I am confused as to why it would find the library when using 64 bit jdk and will not in 32 bit jdk. 我对为什么使用64位jdk而不是32位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)

How do i get the 32 bit jdk to locate the same files? 我如何获取32位jdk来定位相同的文件?

IF I understand your question and problem correctly, then you might try either of: 如果我正确理解了您的问题,那么您可以尝试以下任一方法:

  1. Windows 7 place your 32-bit DLLs into \\Windows\\SysWOW64 instead of \\Windows\\System32. Windows 7将您的32位DLL放入\\ Windows \\ SysWOW64而不是\\ Windows \\ System32。 Oddly enough, under Win 7, System32 is for 64-bit binaries only. 奇怪的是,在Win 7下,System32仅适用于64位二进制文​​件。 See this and this for details. 这个这个有关详细信息。

  2. Better still, place your binary files in an application folder, and specify on the java command line: 更好的是,将二进制文件放在应用程序文件夹中,并在java命令行上指定:

    -Djava.library.path=<path-to-dll-lib>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM