首页>代码>spring boot集成sigar极简入门实例>/springboot-sigar/src/main/java/com/simon/springbootsigar/sigar/SigarUtil.java
package com.simon.springbootsigar.sigar;
import com.google.common.io.Resources;
import org.hyperic.sigar.Sigar;
import java.io.File;
/**
* @author Simon
*/
public class SigarUtil {
public final static Sigar sigar = initSigar();
public static Sigar initSigar() {
try {
String file = Resources.getResource("sigar/.sigar_shellrc").getFile();
File classPath = new File(file).getParentFile();
String path = System.getProperty("java.library.path");
if (OsCheck.getOperatingSystemType() == OsCheck.OSType.Windows) {
path += ";" + classPath.getCanonicalPath();
} else {
path += ":" + classPath.getCanonicalPath();
}
System.setProperty("java.library.path", path);
return new Sigar();
} catch (Exception e) {
return null;
}
}
}

最近下载
最近浏览