Import a DLL into a Java Eclipse project

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

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

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

 System.loadLibrary("myAPI.dll"); 

And received an 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 other other directories mentioned in path . But each time I got the same error message. How to solve this problem?

+4
source share
3 answers

Do not put ".dll" at the end of your library. This extension is for Windows, and your call will work on other systems with other extensions, so installing the extension on it is incorrect. Just download "myAPI", and if rights names and other things are advertised, they will work.

+5
source

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

This is the easiest way to find out. This work is for me. Hope they help you. :)

+1
source

If the dll is in the folder of your project (for example, part of your project), that is:

 ./prod/bin/myAPI.dll 

and you want to run the / unit test program inside eclipse, you can configure the runtime environment that runs your program. Go to the "Preferences / Java / Installed JREs" section, select the required JRE or JDK (note: to load a 32-bit DLL you must use a 32-bit JRE, although your host system is a 64-bit system), click "Change " In the "VM default arguments" field, you enter

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

This adds your dll "prod / bin" folder in front of the system path (do not worry, this is not permanent, only for the environment selected by the JRE).

By running the following code, you can verify that the system path has been updated and the DLL can be downloaded:

  String path = System.getProperty("java.library.path"); System.out.println(path); System.loadLibrary("myAPI"); 
0
source

Source: https://habr.com/ru/post/1393504/


All Articles