views:

1430

answers:

3

Hello,

I have written some JNI hooks into a C++ library and created some DLL files for my java server project. Lets say the DLL and jar files are in the same folder under "C:/server"

I am accessing these DLL files using:

System.loadLibrary("someDLLFile");

in the class that needs the C++ code.

The problem I am running into is when I run this server on my own machine, everything works fine regardless of where I place the "server" folder. But when I give it to a colleague to test, they continually get:

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

I want to have the DLL files live in the same folder as the jar files and would prefer not having someone configure their PATH variable.

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

+3  A: 

It works because the DLL (or a DLL it depends on, i.e. msvcr90.dll or something) are in the PATH on your machine, but not on the other one.

Either set PATH env-var or the java.library.path property to contain the dir with your file, or store your dll where java finds it by default (Many options here, depending on deployment strategy and platform).

Marcus Lindblom
+1  A: 

One option is to specify the directory in the command line when you start the VM:

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

Another option is to use System.load instead of System.loadLibrary.

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

The downside is that your program is now dealing with platform-dependent directory names, file extensions etc.

finnw
A: 

I'm not sure if this is helpful or not, but I have included the following in some projects:

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

To load native libraries.

And then I just load the bin directory

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

   addDir( binPath );

It works pretty well.

But Again, I'm not sure if this is the case or not.

OscarRyz