Native libraries as resources

This is a workaround for the lack of support for native library loading

My current apporach is to load the dll files using part of the resource mechanism. Let say I have these dlls:

           xfiledialog.dll       xfiledialog64.dll

in a certain module/package of my project.

In the same folder than the dlls there is the class that loads them, let say This class must include some code like this:


String dllName="xfiledialog"

public static final String fullDllName;
      static {
        URL url = DllLoader.class.getResource("");
        String path = url.getFile();
        File file = new File(path, dllName);
        if (System.getProperty("os.arch").indexOf("64") >= 0) fullDllName= file + "64.dll";
        else fullDllName= file.toString();



Everything works fine but one thing: I must copy the "resouce" dlls to the output folder by hand. Even I have added  "*.dll" to the resources types in Setting>Compiler dialog, IDEA (96.1190) don't copies these files to the output folder. Some sort  of renaming extension mechanism.would be nedded for automaic deployement of a module with native dependencies.

1 comment

I have a similar problem.

I create a jar artifact with all other dependencies included, except the native library.

When i run the jar artifact. the code tries to find the native library inside eg. out/artifact/test.jar/source/main/java/native.dll and fails, becausethe dll  is not packed inside.


Please sign in to leave a comment.