• 使用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();  
            }  
      
        }  
  • 相关阅读:
    ISP基础(01):ISP模块列表
    Linux 开发(02):打印特殊含义转义符
    note template
    apply、call、bind的区别
    Fiddle 抓包工具
    post和get的使用场景和区别
    闭包
    原型链
    node.js
    CSS垂直居中
  • 原文地址:https://www.cnblogs.com/kasher/p/7513818.html
Copyright © 2020-2023  润新知