Why can my Java project call my DLLs successfully in Eclipse when I place them in JAVA_HOME\jre6\bin but failed in using java.library.path?

StackOverflow https://stackoverflow.com/questions/10827045

Question

After doing some research, some people say I can add the following VM Argument in my project Run Configuration. In run time, JVM will search these directories to find DDLs.

-Djava.library.path="${workspace_loc}/GunCalibration/myLib/DLLs;${env_var:PATH}"

GunCalibration is my Java project folder in my workspace. DLLs folder contains all my DLLs which are defined with my JNI specification.

As a result, I get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Software x64\eclipse3.7\Kai\workspace_RealW\GunCalibration\myLib\DLLs\sixense.dll: Can't find dependent libraries

However, if I copy some specific dll files to JAVA_HOME\jre6\bin, my code works correctly. (I do add this path into my system environment PATH.)

Could anyone explain why the first approach by using java.library.path doesn't work? How can I know which ddl is required to place in JAVA_HOME\jre6\bin?

Thank you a lot~

Was it helpful?

Solution

JAVA_HOME\jre6\bin is effectively in the system PATH (since it's the same directory as the java.exe program which is being run), which makes any DLLs there loadable by the system. java.library.path is mostly derived from the value of PATH, but it only affects where the VM looks for native libraries, not the system itself.

The VM can load any file explicitly based on the paths in java.library.path, but it cannot affect how the system looks up any dependent DLLs (other than telling the system to include the path to the initial DLL in its search -- see MSDN for LoadLibrary[Ex])

One alternative to copying the DLLs is to add the path to the DLLs to the PATH environment variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top