eclipse 如何在 Java 项目中包含 SIGAR API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12214114/
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
How to include SIGAR API in Java Project
提问by Marcus Se
I'm new on Java, so i don't know who to get the downloading zip-file (hyperic-sigar-1.6.4.zip) in the project where i've to use the Sigar-classes.
我是 Java 新手,所以我不知道在我必须使用 Sigar 类的项目中从谁那里获取下载的 zip 文件(hyperic-sigar-1.6.4.zip)。
I already try to import the Sigar.Jar file, but the problem is then that the sources are unknown for each class in sigar.
我已经尝试导入 Sigar.Jar 文件,但问题是 sigar 中每个类的来源都是未知的。
So i use Eclipse Indigo for programming, may someone can help me :)
所以我使用 Eclipse Indigo 进行编程,有人可以帮助我:)
Very Thanksfull greets
非常感谢问候
Marcus
马库斯
采纳答案by Vinesh
First You need to add Sigar.jar
to your library, then add .so
file to your library (you need to pick file for your OS what you are using). You can find these files in "hyperic-sigar-1.6.4/sigar-bin/lib"
. You can find the usage of Mem
function in the example code:
首先您需要添加Sigar.jar
到您的库中,然后将.so
文件添加到您的库中(您需要为您的操作系统选择您正在使用的文件)。您可以在"hyperic-sigar-1.6.4/sigar-bin/lib"
. 您可以Mem
在示例代码中找到函数的用法:
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
public class MemExample {
private static Sigar sigar = new Sigar();
public static void getInformationsAboutMemory() {
System.out.println("**************************************");
System.out.println("*** Informations about the Memory: ***");
System.out.println("**************************************\n");
Mem mem = null;
try {
mem = sigar.getMem();
} catch (SigarException se) {
se.printStackTrace();
}
System.out.println("Actual total free system memory: "
+ mem.getActualFree() / 1024 / 1024+ " MB");
System.out.println("Actual total used system memory: "
+ mem.getActualUsed() / 1024 / 1024 + " MB");
System.out.println("Total free system memory ......: " + mem.getFree()
/ 1024 / 1024+ " MB");
System.out.println("System Random Access Memory....: " + mem.getRam()
+ " MB");
System.out.println("Total system memory............: " + mem.getTotal()
/ 1024 / 1024+ " MB");
System.out.println("Total used system memory.......: " + mem.getUsed()
/ 1024 / 1024+ " MB");
System.out.println("\n**************************************\n");
}
public static void main(String[] args) throws Exception{
getInformationsAboutMemory();
}
}
回答by Jamie Burke
The downloaded zip will contain a folder or two giving examples in how to use some of the functions. Example of the folder can be found at:
下载的 zip 将包含一个或两个文件夹,给出如何使用某些功能的示例。可以在以下位置找到文件夹的示例:
"hyperic-sigar-1.6.4/bindings/java/examples"
“hyperic-sigar-1.6.4/bindings/java/examples”