zoukankan      html  css  js  c++  java
  • windows 下tomcat重启脚本

    @echo off&setlocal enabledelayedexpansion
    @rem (start /min cmd.exe /c %0 :&exit)
    start /min 
    title Tomcat 重启脚本%1
    cd ..
    set CATALINA_HOME=%cd%
    set STR_TASK=%1
    set JAVA_HOME=%CATALINA_HOME%injdk1.7.0_55
    cd /D %CATALINA_HOME%in
    call %CATALINA_HOME%inshutdown.bat
    ping -n 3 localhost >nul
    wmic process where name="java.exe" get processid,commandline |findstr /i %STR_TASK%  >#
    for /f "delims=*" %%i in (#) do (      
       set var=%%i
       set var=!var:start= #!
       for /f "tokens=3 delims=#" %%a in ("!var!") do (set tomcatpid=%%a)
    )
    del # >nul
    if defined tomcatpid taskkill /pid !tomcatpid!
    ping -n 3 localhost >nul
    call %CATALINA_HOME%instartup.bat
    
    taskkill /im cmd.exe

    由于windows的任务不好锁定,所以执行的时候,需要传入tomcat的主目录的名称用来锁定进程号,保证运行的tomcat中没有重复的文件名。

    下面是我代码的调用示例

    String cmdcommand = "";
                String osname = System.getProperties().getProperty("os.name").toLowerCase();
                File  partfile = new File(new  File(ServerDirUtils.getServerRoot()).getParent());
                String rootdirpath = partfile.getParent();
                String rootname = partfile.getParentFile().getName();
                if(!osname.toLowerCase().contains("windows")){
                    String rootPath = rootdirpath +File.separator+"bin"+File.separator+"restart.sh";
                    cmdcommand = "sh "+rootPath+   "  "+rootname;
                }else{
                    String rootPath = rootdirpath+File.separator+"bin"+File.separator+"restart.bat";
                    cmdcommand = "cmd /c start "+rootPath+"  "+rootname;
                }
                logger.error("执行的命令为:"+cmdcommand);
                try {
                    Runtime.getRuntime().exec(cmdcommand);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

    如假如我的tomcat的目录为D:zhkapache-tomcat-8.5.39

    那命令的组成为:

    cmdcommand = "cmd /c start  【你的重启bat的所在的位置,建议放在bin目录下】  apache-tomcat-8.5.39

  • 相关阅读:
    【JZOJ3188】找数【数论,数学】
    【JZOJ3187】的士【模拟】
    【JZOJ3187】的士【模拟】
    【洛谷P1641】生成字符串【数论,数学】
    【洛谷P1896】互不侵犯【状压dp】
    聚集索引与非聚集索引
    哈希索引
    索引能提高检索速度,降低维护速度
    MySQL索引基本知识
    注解
  • 原文地址:https://www.cnblogs.com/zhanghongke/p/13032453.html
Copyright © 2011-2022 走看看