Java, System.loadlibrary ("someDLLFile") gets an unsatisfied link error

I wrote some JNI hooks to the C ++ library and created some DLL files for my java server project. Let's say the DLL and jar files are in the same folder in the "C: / server" folder

I access these DLL files using:

System.loadLibrary("someDLLFile");

in a class that needs C ++ code.

The problem I am facing is when I run this server on my machine, everything works fine, regardless of where I put the server folder. But when I give this to a colleague for testing, they constantly get:

java.lang.UnsatisfiedLinkError no someDLLFile in java.library.path

I want the dll files to work in the same folder as the jar files, and would prefer that someone not configure their PATH variable.

Why does System.loadLibrary () work on my own computer, regardless of the location of the folder, but not on another computer?

+1
source share
4 answers

This works because the DLL (or the DLL on which it depends, i.e. msvcr90.dll or something else) is located in the PATH on your computer, but not on the other.

Either set PATH env-var, or the java.library.path property to contain the directory with your file, or store your DLL where java finds it by default (there are a lot of options, depending on the deployment strategy and platform).

+4
source

One option is to specify the directory on the command line when starting the virtual machine:

java -classpath C:\server -Djava.library.path=C:\server somePackage.Main

- System.load System.loadLibrary.

URL url = Test.class.getResource("someDLLFile.dll");
String f = new File(url.getFile()).getAbsolutePath();
System.load(f);

, , ..

+1

, , :

http://forums.sun.com/thread.jspa?threadID=707176

.

bin

    String binPath = new File(".").getAbsolutePath() 
                     + System.getProperty("file.separator") + "bin";

   addDir( binPath );

.

, , .

0

depend.exe, , dll DLL . , , DLL .

0

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


All Articles