由于需要在固定的时候对tomcat进行关闭,所以写了个小例子,利用cmd命令对tomcat进行重启


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("关闭");

       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("关闭cmd进程");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}