Struggeling with JNI in WIndowsXP....

A

Arne Styve

Hi,

I have a project where I use JNI to get access to a relatively simple C++
library provided as 3 DLLs. This library only requires the msv*.dll-files to
be present on the target machine to run.

I've created a class A with native methods, generated the corresponding C++
headerfile, and the guy coding the C++ library has implemented the
headerfile in a C++ file. Now his C++ library uses two other DLL's, in
adition to the msv*.dll's.

In Java, I load the DLL using

static { System.loadLibrary("testDll");}

When running my program, I have my application JAR placed in the same
directory as the 3 DLL's. I've also added the 3 msv*.dll-files to this
directory, including the Microsoft.VC80.CRT.manifest-file.
When running on my PC, it all works just fine, but when I move my JAR-file,
and all the DLL's and the manifest file to a different PC, I get the
following message:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
C:\Programfiler\OSC\test\testDll.dll:
An initiallisationroutine for a library with dynamic loading (DLL) failed
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at test.<clinit>(test.java:32)
at testModel.<init>(testModel.java:115)
at main(main.java:81)
at main.main(main.java:142)

NB! The text "An initiallisationroutine for a library for dynamic loading
(DLL) failed" is an attempted translation of the Norwegian:
"En initialiseringsrutine for et bibliotek for dynamiske koblinger (DLL)
mislyktes"

I've also tried installing the Microsoft Redistributable as described in
http://www.microsoft.com/downloads/...EE-A3F9-4C13-9C99-220B62A191EE&displaylang=en
without success.

I've put my files on a memorystick, and tried running the application
directly from the stick on several PC's at our office, and on most of the
PC's the application runs fine, but on some of them I get the errormessage
above.

I've figured out that the Java-code does find the testDll.dll-file,
otherwise the errormessage would state:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no testDll in
java.library.path

...so I recon the error is within the test.dll-file, i.e. it is not able to
find the other dll's it is dependent on. I've tried DependencyWalker too,
but cannot find any differences between the PC's where it works, and the
PC's where it does not work.

The test.dll has it's manifest embedded by the way.

Anyone experienced a similar problem ?

What is the best practice when using JNI to access code developed with
MSVisual Studio ?

Regards
Arne
 
S

Sanjay

Exception in thread "main" java.lang.UnsatisfiedLinkError: no testDll in
java.library.path

You never mentioned how exactly you run your jar file. Try adding this

-Djava.library.path=./
 
A

Arne Styve

You never mentioned how exactly you run your jar file. Try adding this

-Djava.library.path=./

Hi Sanjay,

Sorry, I forgot.

I've tried

c:...>java -Djava.library.path=./ -cp test.jar testApp

And I've built the JAR with manifest ("executable JAR"), and started it:

c:...>java -jar testApp.jar

....but with the same result.

I think the problem is related to the side-by-side assembley stuff from
Microsoft.

Arne
 
S

Sanjay

Arne said:
Hi Sanjay,

Sorry, I forgot.

I've tried

c:...>java -Djava.library.path=./ -cp test.jar testApp

And I've built the JAR with manifest ("executable JAR"), and started it:

c:...>java -jar testApp.jar

...but with the same result.

I think the problem is related to the side-by-side assembley stuff from
Microsoft.

Arne
Its been a while since I wrote any JNI code. Besides I develop mostly on
Linux.

On Linux, if I get same error I would put all my libraries (.so) in
LD_LIBRARY_PATH environmental variable. I would also use ld. I am not
sure how you would do that on Windows though.
 
Z

Zig

..so I recon the error is within the test.dll-file, i.e. it is not able
to
find the other dll's it is dependent on. I've tried DependencyWalker too,
but cannot find any differences between the PC's where it works, and the
PC's where it does not work.

Do Start -> Run -> compmgmt.msc

and look under System Tools -> Event Viewer -> Application

The OS should log DLL problems there, so you can get some better
information about what's going on...

HTH,

-Zig
 
A

Arne Styve

Its been a while since I wrote any JNI code. Besides I develop mostly on
Linux.

On Linux, if I get same error I would put all my libraries (.so) in
LD_LIBRARY_PATH environmental variable. I would also use ld. I am not sure
how you would do that on Windows though.

Hi again,

Thanks for trying to help me out here.

I've solved the problem (temporarely) by running an Windows Update on the
PC, and installed the Microsoft Visual Studio 2005 Redistributable SP1. I'm
not 100% confortable with this solution, but it'll have to do for now...

Regards
Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top