How to configure .dll file in Java?

…衆ロ難τιáo~ 提交于 2019-11-29 04:22:42

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.

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.

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.

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

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.

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!