我有MyCpu java类,该类运行良好,我需要将输出显示到仅尝试使用JSP的网页中,但它不起作用,然后我添加了JSTL标记库并添加了此代码-Djava.library.path = “ ./lib”到MANIFEST.MF
我也在使用Sigar API,并添加到库中,然后出现此错误:
java.lang.UnsatisfiedLinkError:org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg / hyperic / sigar / CpuInfo;
有什么帮助或建议吗?
package mydata;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
public class MyCpu {
private String cpuInfoList;
public String getCpuInfoList(){
return this.cpuInfoList;
}
public MyCpu() {
Sigar sigar = new Sigar();
String output = " ";
CpuInfo[] cpuInfoList = null;
try {
cpuInfoList = sigar.getCpuInfoList();
} catch (SigarException e) {
e.printStackTrace();
return;
}
for (CpuInfo info : cpuInfoList) {
output += "Vendor: " + info.getVendor() + "\n";
output += "Model: " + info.getModel() + "";
output += "DD:" +info.toString()+ "";
}
System.out.println(output);
}
public static void main(String[] args) {
MyCpu main = new MyCpu();
}
}
----------------------------------------------------------------------------------
<%@page import="mydata.MyCpu"%>
<%@page import ="org.hyperic.sigar.Sigar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
MyCpu cpu = new MyCpu();
Sigar sigar = new Sigar();
out.println(sigar.getCpuInfoList()[4]);
%>
</body>
</html>
最佳答案
尝试将其添加为JVM参数
-Djava.library.path="./lib"