使用java代碼重啟tomcat


private static    String location="F:\\apache-tomcat-7.0.62";

private static void executeCmd(String location) {
        System.out.println(location);
        Runtime run = Runtime.getRuntime();
        try {
            Process ps = run.exec("" + location + "\\bin\\restart.bat");
            // 我很奇怪 下面的代碼去掉的話 tomcat的黑框就不能出現
            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream(), "GBK"));// 注意中文編碼問題
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println("StartedLog==>" + line);
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    
    private static void createCmdFile(String location) {  
        File f = new File(location + "\\bin\\restart.bat");  
        try {  
            FileWriter fw = new FileWriter(f);  
            BufferedWriter bw = new BufferedWriter(fw);  
             //下面的必須加上  
            bw.write("set CATALINA_HOME=" + location);  
            bw.newLine();  
            bw.write("call " + location + "\\bin\\shutdown.bat");  
            bw.newLine();  
            bw.write(" ping 127.0.0.1 -n 5  1>nul ");  
            bw.newLine();  
            bw.write("call " + location + "\\bin\\startup.bat ");  
  
            bw.close();  
            fw.close();  
        } catch (Exception e1) {  
            // TODO Auto-generated catch block  
            e1.printStackTrace();  
        }  
  
    }  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM