Chr*_*ris 5 java hyperic sigar
嗨我使用第三方lib名称Hyperic Sigar.当我运行我的代码时,它显示错误,
这是我的代码:
package pack;
import org.hyperic.sigar.*;
public class NetworkData {
public static void main(String[] args) {
Sigar sigar = new Sigar();
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
1 [main] DEBUG Sigar - no libsigar-universal64-macosx.dylib in java.library.path
org.hyperic.sigar.SigarException: no libsigar-universal64-macosx.dylib in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at pack.NetworkData.main(NetworkData.java:10)
Run Code Online (Sandbox Code Playgroud)
我在Mac Osx Snow Leopard上开发使用Eclipse IDE for Java开发人员发现了一些旧帖子(在java.library.path中没有sigar-x86-winnt.dll)在多语言操作系统上使用Hyperic SIGAR时出错.帖子说我需要添加一些路径,如果是这样...我如何在Mac Osx中添加该路径?希望有人可以帮助^^
# to find it later because you will need it ...
cd ~/Downloads/
# or whatever the latest one at the time of reading is ...
curl https://netix.dl.sourceforge.net/project/sigar/sigar/1.6/hyperic-sigar-1.6.4.zip
# unpack the package to the tmp dir
sudo unzip -o /Users/phz/Downloads/hyperic-sigar-1.6.4.zip -d /tmp/
# copy the libsigar-universal64-macosx.dylib to your class path dir
sudo find /tmp/ -name libsigar-universal64-macosx.dylib \
-exec cp -v {} /Library/Java/Extensions/ \;
# this cmd might be obsolete ...
# copy the sigar.jar to your class path dir
sudo find /tmp/ -name sigar*.jar \
-exec cp -v {} /Library/Java/Extensions/ \;
# set you classpath dir, or add in ~/.bash_profile
# or even better https://github.com/YordanGeorgiev/ysg-confs
export CLASSPATH=$CLASSPATH:/Library/Java/Extensions
# you should not see the error anymore
cd $my_proj_dir ; sbt compile
# neither here ..
cd $my_project_dir ; clear ; sbt "test:testOnly *testClass"
Run Code Online (Sandbox Code Playgroud)
首先,您需要添加Sigar.jar到您的库,然后将 .dylib 文件添加到您的库(您需要为您正在使用的操作系统选择文件)。在您的情况下,您应该添加libsigar-universal64-macosx.dylib您可以在 中找到这些文件"hyperic-sigar-1.6.4/sigar-bin/lib"。