Loading DLL in Java - Eclipse - JNI

后端 未结 9 442
北荒
北荒 2020-12-17 18:19

I am trying to load a dll in java using the following code System.loadLibrary(\"mydll\");

The project is placed in D:\\development\\project\\ and i have placed t

相关标签:
9条回答
  • 2020-12-17 18:58

    Using System.loadLibrary("mydll") works fine, you can also use that one. If you used javah and you think with your DLL everything is fine, there are two possibilies:

    1. The JVM does not find your DLL: In this case, your java library path is not correct (which I doubt) and you should probably set it to . and place your DLL in the current working dir.
    2. The JVM does not find a DLL your DLL depends on: If you have any dependent libraries in your DLL, they are NOT searched by the JVM, but by Windows itself. And Windows does not know the java.library.path, so it will look in the system PATH variable for those. If you have the possibility, you can set the system PATH variable to the location of your DLLs before starting the JVM and everything will be fine. Or you can load all your DLLs using the JVM like this

      System.loadLibrary("dll_1");
      System.loadLibrary("dll_2");
      System.loadLibrary("dll_3");

      where dll_3.dll depends on dll_2.dll, which depends on dll_1.dll.

    Hope that helps.

    0 讨论(0)
  • 2020-12-17 18:58

    Give the library path in your project as native library location,seems to be solved.

    0 讨论(0)
  • 2020-12-17 19:00

    @alee- You can just copy and the paste the dll files in system32 folder of your windows and try to call the library through the System.loadLibrary("mydll")... i guess it may work...

    0 讨论(0)
提交回复
热议问题