java Sigar UnsatisfiedLinkError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11612711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:47:03  来源:igfitidea点击:

Sigar UnsatisfiedLinkError

javadebuggingsigar

提问by Narges

I'm new to Sigar. I would like to run a simple test to know how I can monitor my system.

我是 Sigar 的新手。我想运行一个简单的测试来了解如何监控我的系统。

I added sigar-1.6.4and log4jas external libraries, but when I go to run it, I face this error:

我添加了sigar-1.6.4log4j作为外部库,但是当我去运行它时,我遇到了这个错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo; at org.hyperic.sigar.Sigar.getCpuInfoList(Native Method)

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo; at org.hyperic.sigar.Sigar.getCpuInfoList(Native Method)

Here is my code:

这是我的代码:

import java.util.Map;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Sigar sigar = new Sigar();
        CpuInfo[] cpuinfo = null;
        try {
        cpuinfo = sigar.getCpuInfoList();
        } catch (SigarException se) {
        se.printStackTrace();
        }

        System.out.println("---------------------");
        System.out.println("Sigar found " + cpuinfo.length + " CPU(s)!");
        System.out.println("---------------------");
    }

}

Any help would be appreciated.

任何帮助,将不胜感激。

回答by Narges

I understood the problem!
I have to use the following JVM Argument:

我明白了问题所在!
我必须使用以下 JVM 参数:

-Djava.library.path="./lib" 

in Run Configuration, Arguments tab, VM arguments in eclipse, while the contnet of sigar-bin/lib is in lib folder.

在运行配置中的参数选项卡中,eclipse 中的虚拟机参数,而 sigar-bin/lib 的内容在 lib 文件夹中。

回答by Vishal Rao

Sigar works via JNI. As such, the appropriate .so or .dll file needs to be in the path specified by the java.library.path property.

Sigar 通过 JNI 工作。因此,适当的 .so 或 .dll 文件需要位于 java.library.path 属性指定的路径中。

Check your sigar distribution - the zip file, I mean. Unzip it and copy the contents of sigar-bin\lib to a location accessible by your Path, PATH, and LD_LIBRARY_PATH environment variables. Usually, only one file needs to be accessible per platform.

检查您的 sigar 发行版 - 我的意思是 zip 文件。解压缩并将 sigar-bin\lib 的内容复制到您的 Path、PATH 和 LD_LIBRARY_PATH 环境变量可访问的位置。通常,每个平台只需访问一个文件。

That should do the trick, if it doesn't, let me know and I'll see what I can do.

这应该可以解决问题,如果没有,请告诉我,我会看看我能做什么。