如何在Java Project中包含SIGAR API [英] How to include SIGAR API in Java Project

查看:116
本文介绍了如何在Java Project中包含SIGAR API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手,所以我不知道谁在使用Sigar类的项目中获得下载zip文件(hyperic-sigar-1.6.4.zip)。



我已经尝试导入Sigar.Jar文件,但是问题是,每个类的来源在sigar中是未知的。



所以我使用Eclipse Indigo进行编程,有人可以帮助我:)



非常感谢grep



Marcus

解决方案

首先您需要添加 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(***关于内存的信息:***);
System.out.println(************************************ \
);

Mem mem = null;
try {
mem = sigar.getMem();
} catch(SigarException se){
se.printStackTrace();
}

System.out.println(实际总的免费系统内存:
+ mem.getActualFree()/ 1024 / 1024+MB);
System.out.println(实际总使用系统内存:
+ 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(总系统内存............:+ mem.getTotal()
/ 1024 / 1024+MB);
System.out.println(Total used system memory .......:+ mem.getUsed()
/ 1024 / 1024+MB);

System.out.println(\ ****************************** ****** \\\
);


}

public static void main(String [] args)throws异常{

getInformationsAboutMemory();

}

}


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.

I already try to import the Sigar.Jar file, but the problem is then that the sources are unknown for each class in sigar.

So i use Eclipse Indigo for programming, may someone can help me :)

Very Thanksfull greets

Marcus

解决方案

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:

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

                }

}

这篇关于如何在Java Project中包含SIGAR API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆