简体   繁体   中英

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. 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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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