“no sigar-x86-winnt.dll in java.library.path” error when using Hyperic SIGAR on multi language OS

大憨熊 提交于 2019-12-13 13:09:01

问题


I am using a Hyperic SIGAR library as third party lib in my installation program. My installation program unpacks all third lib files to the %TEMP%\\user folder.

On English OS's everything works great, but when i tried to run my setup program on Spanish Os, I've encountered the following error:

the java library includes the sigar.jar:

java.class.path=C:\DOCUME~1\Spanish Letters\CONFIG~1\Temp\e4j58.tmp_dir\user\sigar.jar

My installation program supports WinXP, WIN7 OS's.

The Error is:

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)'

Is someone already encountered a similar error and can advise? Thanks.


回答1:


sigar-x86-winnt.dll put in the current user directory, it will work




回答2:


you should set System property (java.library.path)

ex) java ... -Djava.library.path=../lib/sigar/lib ...

java.library.path is folder that contain the sigar-x86-winnt.dll

https://forums.oracle.com/forums/thread.jspa?threadID=1299532




回答3:


You could also add to java.path.library at runtime programmatically.

    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);

A very good explanation is found at : http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html




回答4:


as discussed in the docs, SIGAR uses JNI underneath. You have to include appropriate JNI file in the path (file is usually displayed in the stack trace). If you are using maven to build the project, you should edit pom.xml to add this file to the path(alas, you cant specify artifact and assume it is going to be in path)

 <!-- add sigar dll to java path -->
                <configuration>
                    <forkMode>once</forkMode>
                    <workingDirectory>target</workingDirectory>
                    <argLine>-Djava.library.path=${basedir}/lib</argLine>
                </configuration>


来源:https://stackoverflow.com/questions/8832751/no-sigar-x86-winnt-dll-in-java-library-path-error-when-using-hyperic-sigar-on

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