如何在Java中配置.dll文件? [英] How to configure .dll file in Java?
问题描述
我在我的java应用程序中使用 Jacob jar文件。
I am using Jacob jar file in my java application.
这个Jacob jar文件附带一个.dll文件。我已经将Jacob jar文件添加到我的类路径。但是当我执行我的应用程序时,出现运行时错误,因为
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"
如何加载.dll文件?
How can I load this .dll file?
编辑:==========================================
Edited:=================================================================================
我已经将包含我的.dll文件的dir文件的路径环境变量设置为如下。
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");
}
但发生以下错误
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)
推荐答案
jacob-1.15-M3-x86.dll需要位于操作系统可以找到的位置。您有几个选项:
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:
-
您可以将.dll文件放在您启动应用程序的目录中。如果您有一个批处理脚本启动您的应用程序,那将是该目录。如果您从某种应用程序服务器启动,通常是bin目录。
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.
您可以将.dll文件放在% PATH%环境变量。我可能会更容易地更新您的PATH环境变量以包含包含.dll文件的目录。
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.
另一个选项是将.dll放入%SystemRoot%\system32目录。通常这是'C:\Windows\system32'。通常不建议使用此选项,除非是像MSCVRT运行时一样的共享库。
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.
另一个可能的问题有。如果.dll被编译为32位,则必须在32位Java运行时中运行。同样,如果它是一个64位的.dll,它需要在64位JRE中运行。
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.
这篇关于如何在Java中配置.dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!