views:

1222

answers:

4

I am using Jacob jar file in my java application.

This Jacob jar file comes with a .dll file. I have added Jacob jar file to my classpath. But when I execute my application a runtime error occurs as

"couldn't load jacob-1.15-M3-x86.dll file"

How can I load this .dll file?

Edited:=================================================================================

I had set the "path" environment varaible to the dir that contains my .dll file and loading that .dll file as follows

static {
    System.loadLibrary("jacob-1.15-M3-x86.dll");
}

but the following error occured

    java.lang.UnsatisfiedLinkError: no jacob-1.15-M3-x86.dll in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at TemplateClass.TemplateClass.<clinit>(TemplateClass.java:14)
+1  A: 

Ah, that's not a compilation error but a runtime error.

My guess would be that your DLL needs to be on the PATH. Not CLASSPATH, but PATH, because that's where Windows looks for DLLs. Try either extending your PATH to include the location of your DLL, or do what many other people do: Dump the DLL into \Winnt\System\System32 or whatever the system directory is called on your box. Wherever all the other DLLs are, in other words.

Update

The error message you post, thankfully, is pointing out the exact problem. You can solve it by putting the directory containing your DLL into java.library.path This Sun forum thread shows a nice example: http://forums.sun.com/thread.jspa?threadID=627890

Actually, that's a lot less clean than it should be; this seems to be one of the "shadier" areas in Java. The thread wanders around a lot, I do advise you to read all the way through to see some problems and solutions. I think you'll be able to succeed with a little trial and error.

Carl Smotricz
Yes, It is a runtime error. I wrote it by mistake. Thanks.
Yatendra Goel
Could you please look at the edited question?
Yatendra Goel
+2  A: 

The 'jacob-1.15-M3-x86.dll' needs to be in a place where your the operating system can find it. You have a few options here:

  • You can place the .dll file in the directory you started your application from. If you have a batch script to start your application, it would be that directory. If you are starting in some sort of application server, it would typically be the 'bin' directory.

  • You can place the .dll file somewhere in the %PATH% environment variable. I may be easier to just update your PATH environment variable to include the directory that contains your .dll file.

  • Another option is to place your .dll into the %SystemRoot%\system32 directory. Usually this is 'C:\Windows\system32'. This option is not usually recommended unless it is a shared library like the MSCVRT runtime.

One other possible issue you might have. If the .dll is compiled as 32-bit, then you must be running in the 32-bit Java runtime. Likewise, if it is a 64-bit .dll it needs to be run in a 64-bit JRE.

Chris Dail
My problem is solved. Thanks for that.{...You can place the .dll file in the directory you started your application from} Do you mean that the dir where the main class resides? If yes, then why the file should be in the dir where my batch script resides if I use batch script?Could you please explain your first point with more focus on the point when I want to start in an application server?
Yatendra Goel
Could you please look at the edited question?
Yatendra Goel
It should be in the directory where you start the Java process from, not your main class directory.
Chris Dail
+1  A: 

You need to set LD_LIBRARY_PATH. This will give you all the right steps to follow.

duffymo
That's assuming he's running on Linux, right?
Carl Smotricz
If he's running on Linux, JACOB will not be very useful!
finnw
A: 

Other options :

  • set the property java.library.path to the directory containing the dll. Example : java -Djava.library.path="path/to/directory/containing/the/dll" -jar appli.jar
  • in the code, load the dll explicitly, with System.load.
barjak
Both of them are not working.
Yatendra Goel