Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Struggeling with JNI in WIndowsXP....

Thread view: 
Arne Styve - 17 Sep 2007 15:11 GMT
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/details.aspx?FamilyId=32BC1BEE-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
Sanjay - 17 Sep 2007 16:53 GMT
> 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=./
Arne Styve - 18 Sep 2007 07:42 GMT
>> 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=./

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
Sanjay - 18 Sep 2007 20:02 GMT
>>> Exception in thread "main" java.lang.UnsatisfiedLinkError: no testDll in
>>> java.library.path
[quoted text clipped - 21 lines]
>
> 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.
Arne Styve - 24 Sep 2007 07:46 GMT
>> I think the problem is related to the side-by-side assembley stuff from
>> Microsoft.
[quoted text clipped - 6 lines]
> 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
Roedy Green - 18 Sep 2007 12:08 GMT
On Mon, 17 Sep 2007 16:11:56 +0200, "Arne Styve"
<asty@offsimcentre.no> wrote, quoted or indirectly quoted someone who
said :

>Exception in thread "main" java.lang.UnsatisfiedLinkError:

see
http://mindprod.com/jgloss/runerrormessages.html#UNSATISFIEDLINKERROR
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Zig - 18 Sep 2007 21:18 GMT
> ..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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.