4

To import DLL into Eclipse Java project, I checked the "java.library.path"

String path = System.getProperty("java.library.path");
System.out.println(path);

One of the path values was equal to C:/Windows/System32. Therefore I saved myAPI.dll in C:/Windows/System32. Then I called System.loadLibrary:

System.loadLibrary("myAPI.dll");

And got the error message:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: myAPI.dll
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)

BTW, I tried to put my DLL file in different other directories that was mentioned in path. But each time I got the same error message. How to solve this problem?

Perception
  • 79,279
  • 19
  • 185
  • 195
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

3 Answers3

5

Don't put ".dll" at the end of your library. That is a Windows-specific extension, and your call will work on other systems with other extensions, so putting the extension on is incorrect. Just load "myAPI" and, if that's the right names and other things are as advertised, it will work.

arcy
  • 12,845
  • 12
  • 58
  • 103
1

One option is to try keeping that dll in your /jre/bin used in eclipse system library and was able to configure dll files at runtime , by placing dll in /jre/bin

It is the simplest way i could find out. This work for me.Hopefully will help you.:)

0

If the dll is in your project folder (e.g. part of your project), i.e.:

./prod/bin/myAPI.dll

and you want to execute the program/unit test within eclipse you can configure the runtime environment which runs your program. Go to "Preferences/Java/Installed JREs", choose the desired JRE or JDK (note: for loading a 32bit dll you must use a 32bit JRE, although your host system is a 64bit system), click on "Edit". In the box "Default VM arguments" you enter

-Djava.library.path="./prod/bin;${env_var:PATH}"

This adds your dll folder "prod/bin" in front of the system path (don't bother, it's not permanently, only for the environment of the chosen JRE).

By running following code you can verify that the system path was updated and the dll can be loaded:

        String path = System.getProperty("java.library.path");
        System.out.println(path);
        System.loadLibrary("myAPI");
Heri
  • 4,368
  • 1
  • 31
  • 51