How to configure .dll file in Java?
Asked Answered
M

6

8

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)
Miscellaneous answered 17/1, 2010 at 18:8 Comment(1)
placing the dlls in system32 folder of windows solved the issue for meHeadship
F
10

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.

Footrest answered 17/1, 2010 at 18:20 Comment(2)
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?Miscellaneous
It should be in the directory where you start the Java process from, not your main class directory.Footrest
S
5

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.

Swanskin answered 17/1, 2010 at 18:12 Comment(0)
M
3

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.
Mcatee answered 17/1, 2010 at 19:43 Comment(0)
D
1

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

Distiller answered 17/1, 2010 at 18:23 Comment(2)
If he's running on Linux, JACOB will not be very useful!Basketball
I'm assuming that there's an .so for Linux. Same comments apply.Distiller
I
1

When you use System.loadLibrary() don't include the .dll at the end.

Also, if you are not setting java.library.path to point to the folder containing the DLL then the DLL should be in the directory where you launch your Java application from.

Integrator answered 1/11, 2012 at 16:11 Comment(0)
P
0

I had the same problem.

I see that the question is not "answered", so maybe none of the options above worked.

One of my last hypothesis was that the Jacob.dll is missing its dependency.

What I did was to get depend and check if all the dependence, used by Jacob are loaded. Of course this works for Windows.

Cheers!

Penurious answered 23/8, 2011 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.