Search code examples
javac++dlljna

JNA Different behavior on pcs


i have a java program that works with jna and loads a dll. On my develop computer the program runs without problems. But when i run the program on a different pc i get the error that the program cant find the dependet dlls. But my dll depends only on one dll an this dll is inside the same folder.

I run the program as a jar on Windows 7. Dependency walker shows on both pc the same dependecies.

I dont know what the problem or the difference between those computers is.

Why cant the program load the dll?

Error Message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\THZ-standalone\Dlls\BladeTileLocator.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at de.thz.cameracontrol.utils.Utils.loadLibrary(Utils.java:169)
    at de.thz.cameracontrol.server.Server.<init>(Server.java:124)
    at de.thz.cameracontrol.server.Server.main(Server.java:165)

I call the program with java -jar Program.jar. The dlls are saved in a folder (this folder is in the same folder as the java program).

Here is the method for the libray loading:

public static Object loadLibrary(String libraryName, Class<?> clazz) {

final String userDir = System.getProperty("user.dir");
final String filePathToUse = userDir + "\\" + DLL_PATH;

System.setProperty("jna.platform.library.path", filePathToUse);
System.load(filePathToUse + libraryName + ".dll");

return Native.loadLibrary(libraryName, clazz);
// return Native.loadLibrary(libraryName, clazz);

}

I use the statement System.load(filePathToUse + libraryName + ".dll"); for better error messages.


Solution

  • The origin of the problem was a wrong name for the JNA library path system property. The right name is jna.library.path.

    1) Start your application with -Djna.debug_load=true -Djna.debug_load.jna=true to get some information where the JNA library is looking for the DLL.

    2) Shouldn't it be rather jna.library.path instead of jna.platform.library.path.

    3) Maybe you are mixing 32bit/64bit DLL/JVM?