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%\bin\jdk1.7.0_55
cd /D %CATALINA_HOME%\bin
call %CATALINA_HOME%\bin\shutdown.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%\bin\startup.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:\zhk\apache-tomcat-8.5.39

那命令的组成为:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值