Chinaunix首页 | 论坛 | 博客
  • 博客访问: 159227
  • 博文数量: 56
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 593
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-18 09:59
文章分类

全部博文(56)

文章存档

2019年(1)

2018年(26)

2016年(1)

2015年(6)

2014年(22)

我的朋友

分类: 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);




阅读(1329) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~