由于需要在固定的時(shí)候?qū)omcat進(jìn)行關(guān)閉,所以寫了個(gè)小例子,利用cmd命令對tomcat進(jìn)行重啟
public class Restart {
public static void main(String[] args) {
String dir = "C:\\vvv mmm\\apache-tomcat-6.0.30\\bin\\";
Runtime run = Runtime.getRuntime();
String[] command = new String[]{"cmd","/C","call","startup.bat"};
try {
run.exec(command, null, new File(dir));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("啟動");
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("關(guān)閉");
String[] command2 = new String[]{"cmd","/C","call","shutdown.bat"};
try {
run.exec(command2, null, new File(dir));
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(30000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("重啟");
String[] command3 = new String[]{"cmd","/c","start","startup.bat"};
try {
run.exec(command3, null, new File(dir));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("nihao");
try {
Thread.sleep(10000);
String[] command4 = new String[]{"cmd","/c","call","tskill","cmd"};
run.exec(command4);
System.out.println("關(guān)閉cmd進(jìn)程");
} catch (Exception e) {
e.printStackTrace();
}
}
}