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

痞子三分冷 提交于 2019-12-11 02:53:35

问题


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)

How do i get the 32 bit jdk to locate the same files?


回答1:


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. Oddly enough, under Win 7, System32 is for 64-bit binaries only. See this and this for details.

  2. Better still, place your binary files in an application folder, and specify on the java command line:

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



来源:https://stackoverflow.com/questions/12307289/java-loadlibrary-cannot-locate-library-after-switching-from-64-bit-jdk-to-32-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!