分类: Java
2014-09-12 09:49:10
错误的方法:
//CPUID
private static final String cpuid="dmidecode -t processor | grep 'ID' | head -1";
Process p = Runtime.getRuntime().exec(puid);
原因:不会被再次解析,管道符失效
正确的办法:
linux下:
String[] command = { "/bin/sh", "-c", (puid };
Process ps = Runtime.getRuntime().exec(command );
windows下:
String[] command = { "cmd", "/c", (puid };
Process ps = Runtime.getRuntime().exec(command );
//提取jar中webapp、jetty文件夹
if(OSinfo.isWindows()){
Runtime.getRuntime().exec(new String[]{"cmd","/c","IF NOT EXIST jetty/ jar xf *.jar jetty/"});
}
else if(OSinfo.isLinux()){
Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","if [ ! -d \"jetty/\" ]; then\n jar xf *.jar jetty/ \nfi"});
}
Thread.sleep(500);
cfg = new XmlConfiguration(new FileInputStream("./jetty/jetty.xml"));
cfg.configure(server);
//set default descriptor
WebAppContext context = (WebAppContext) server.getHandler().getServer().getHandlers()[0];
String descriptor = Thread.currentThread().getClass().getResource("/jetty/web.xml").toString();
context.setDescriptor(descriptor);