3

Java 1.6 on Windows I am working with a Java library that uses JNI. I want to point it at the DLL's using the java.library.path environment variable, but it doesn't work. When I put the same paths in the PATH variable, it works fine.

Successful case:

C:>set PATH=\Progra~1\Company\Compan~1\lib;\Progra~1\Java\jdk1.6.0_43\bin

(setting path without drive or spaces to try to avoid space issues, though all jars and libraries are on the C drive)

java -cp %CLASSPATH% com.company.samples.ft.MainClass

Unsuccessful case 1:

set PATH=\Progra~1\Java\jdk1.6.0_43\bin C:>java -Djava.library.path=\Progra~1\Company\Compan~1\lib -cp %CLASSPATH% com.company.samples.ft.MainClass ft\FT.cfg Could not load base Company API library Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\Company\Company Client API\lib\CompanyAPI.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028) at com.company.api.CompanyClientAPIImpl.(CompanyClientAPIImpl.ja va:113) at com.company.samples.ft.MainClass.run(MainClass.java:130) at com.company.samples.ft.MainClass.main(MainClass.java:498)

Note that here it did find my DLL but not the dependencies, even though it has the library path from my original Windows PATH. java.library.path does still lack the JDK path, which was and still is in the PATH variable, so let's try adding that to java.library.path:

C:\Program Files\Company\Company Client APIs\samples\jcapi>java -Djava.library.path=\Progra~1\Company\Compan~1\lib;\Progra~1\Java\jdk1.6.0_43\bin -cp %CLASSPATH% com.company.samples.ft.MainClass Could not load base Company API library Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\Company\Company Client API\lib\CompanyAPI.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028) at com.company.api.CompanyClientAPIImpl.(CompanyClientAPIImpl.java:113) at com.company.samples.ft.MainClass.run(MainClass.java:130) at com.company.samples.ft.MainClass.main(MainClass.java:498)

So even with java.library.path looking exactly like my original PATH, the library is not found. Any idea what the problem is here?

Thanks, Mike

MikeS
  • 65
  • 10
  • Did you ever get to the bottom of this? I've been having the exact same problem (although with Java 8) for the past month and it is driving me crazy! – Boomah Sep 12 '17 at 10:55
  • The problem may be that even with java.library.path set correctly, Windows will not look in anything other than its PATH for dependent libraries. Refer to https://bugs.openjdk.java.net/browse/JDK-8213772?focusedCommentId=14222348&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14222348 and https://rgrzywinski.wordpress.com/2006/03/27/cant-find-dependent-libraries/ – zhenguoli Jul 02 '20 at 06:28

0 Answers0