Search code examples
javawindowsintellij-ideadlljna

Native.loadLibrary() returns null when project is a gradle dependency


Implemented a java driver project which exploits some .dll files with help of JNA. It works pretty well as a project when i build and run. However, I am not able to load .dll file when this driver project is jarred and become a dependency to another bigger project.

I am using Native.loadLibrary(LIBRARY_NAME, MY_INTERFACE.class) syntax to load the library in the driver project. This line successfully loads my library in the driver project but returns null when it is a dependency to another project. How can i debug and find out where the problem is?

To reproduce this behavior:

OS: Windows 10 IDE: Intellij Community 2018.2 Java: 1.8.0_191 driver project: https://github.com/ClearControl/GS16AO64c parent project: https://github.com/AhmetCanSolak/clearcontrol


Solution

  • I finally solved my problem. JNA's Native.loadLibrary() was not able to access any non-class element from a jar. I copied the resource .dll files into temp files and first load them with:

    System.load(tmpFile.getAbsolutePath());

    then use Native.loadLibrary(). This way it works.