我在我的安装程序中使用a Hyperic SIGAR库作为第三方库。 我的安装程序将所有第三个lib文件解压缩到%TEMP%\\ user文件夹。
在英语操作系统上,一切都很好,但当我尝试在西班牙语Os上运行我的安装程序时, 我遇到了以下错误:
java库包含sigar.jar:
java.class.path = C:\ DOCUME~1 \ 西班牙语字母 \ CONFIG~1 \ Temp \ e4j58.tmp_dir \ user \ sigar.jar
我的安装程序支持WinXP,WIN7 OS。
错误是:
no sigar-x86-winnt.dll in java.library.path
org.hyperic.sigar.SigarException: no sigar-x86-winnt.dll in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at I4jScript_Internal_1.eval(I4jScript_Internal_1.java:23)
at I4jScript_Internal_1.evaluate(I4jScript_Internal_1.java:79)
at com.install4j.runtime.installer.helper.Script.evaluate(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.beans.actions.control.RunScriptAction.execute(Unknown Source)
at com.install4j.runtime.beans.actions.SystemInstallOrUninstallAction.install(Unknown Source)
at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.performAction(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.executeActions(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.handleCommand(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.handleStartup(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.start(Unknown Source)
at com.install4j.runtime.installer.Installer.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
at com.exe4j.runtime.WinLauncher.main(Unknown Source)
at com.install4j.runtime.launcher.WinLauncher.main(Unknown Source)'
是否有人遇到类似错误并且可以提供建议? 谢谢。
答案 0 :(得分:2)
你应该设置系统属性(java.library.path
)
ex)java ... -Djava.library.path=../lib/sigar/lib ...
java.library.path
是包含sigar-x86-winnt.dll
https://forums.oracle.com/forums/thread.jspa?threadID=1299532
答案 1 :(得分:1)
sigar-x86-winnt.dll放入当前用户目录,它将起作用
答案 2 :(得分:1)
正如文档中所讨论的,SIGAR使用了JNI。您必须在路径中包含适当的JNI文件(文件通常显示在堆栈跟踪中)。 如果您使用maven来构建项目,则应编辑pom.xml以将此文件添加到路径中(唉,您无法指定工件并假设它将在路径中)
<!-- add sigar dll to java path -->
<configuration>
<forkMode>once</forkMode>
<workingDirectory>target</workingDirectory>
<argLine>-Djava.library.path=${basedir}/lib</argLine>
</configuration>
答案 3 :(得分:1)
您也可以在运行时以编程方式添加到java.path.library。
System.setProperty("java.library.path", System.getProperty("java.library.path")+File.pathSeparator+pathToYourDLL);
//set sys_paths to null
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);
可以在http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html
找到一个非常好的解释