【发布时间】:2014-02-24 01:58:56
【问题描述】:
我有一个返回 CPU 值的 GUI 程序,这需要外部 API。我已经制作了 JAR,但除非我在 netbeans IDE 中运行该程序,否则该程序不会返回 CPU。我的问题是如何将 API 打包到 JAR 文件中。
private class getCpu extends Thread {
@Override
public void run() {
while(true) {
try {
Sigar sigar = new Sigar();
Cpu cpu = new Cpu();
CpuPerc perc = sigar.getCpuPerc();
DecimalFormat df = new DecimalFormat("###.###");
//df.format(100-(perc.getIdle()*100));
cpuLabel.setText("CPU : "+df.format(100-(perc.getIdle()*100))+"%");
try{Thread.sleep(1000);}catch(Exception e2){}
}catch(SigarException e1){}
catch(Exception e){}
}
}
}
【问题讨论】:
-
大概是在一些库 JAR 中定义和实现了 API。运行程序时需要确保 JAR 在类路径中。
-
@OliCharlesworth 请给我解释一下