Sigar API Java ClassNotFoundException

时间:2016-07-10 07:56:57

标签: java classnotfoundexception sigar

我已经从他们的网站下载了Sigar API,并将sigar.jar文件包含在我的Eclipse项目中。

但问题是我需要.java个文件才能将我的项目转换为obj-c。

所以我从github下载了zip文件并从sigar-master/bindings/java/src/org/hyperic/sigar复制了src文件夹,但是在它们中找不到一些类。

鉴于示例代码在包含jar时运行正常但是当包含.java文件时,代码未运行。

我哪里错了?

谢谢!

代码:

import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;


import org.hyperic.sigar.Mem; // Eclipse says that The import org.hyperic.sigar.Mem cannot be resolved
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;  // Mem cannot be resolved to a type
    try {
        mem = sigar.getMem();  // The method getMem() from the type Sigar refers to the missing type Mem
    } 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{ // line 45

            getInformationsAboutMemory();

            }

}

控制台:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at MemExample.main(MemExample.java:45)

它说Mem cannot be resolved to a type

当我解压缩sigar.jar时,其中有一个班级Mem.class

0 个答案:

没有答案