A Windows DLL (i.e. a Native Java Library, such as chilkat.dll) may be loaded at runtime by calling System.loadLibrary( dllFilename ), or System.load( dllFilePath ). For example:
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
}
try {
System.load("c:/temp/javaDeployTest/chilkat.dll");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
}
With System.loadLibrary, you only specify the name of the DLL, such as "chilkat". The JVM (java runtime) will search for the DLL in the directories listed in java.library.path system property. This property may be set on the command line with the -D option:
java -Djava.library.path=c:\temp\myNativeDlls myTestApp <strong>NOTE:</strong> There should be no SPACE character between the "-D" and the "java.library.path". The lack of a SPACE character is correct.
The System.load method is more straightforward and allows you to specify the filepath of the native library directly.
本文介绍如何使用Java在运行时加载Windows DLL文件(如本地Java库chilkat.dll)。通过System.loadLibrary或System.load方法实现,并提供了具体的代码示例。同时说明了如何设置java.library.path系统属性来指定DLL搜索路径。
3057

被折叠的 条评论
为什么被折叠?



