根据windows守护tomcat的bat批处理脚本增强功能
原理:发现webapps目录下有新的ROOT.war包进行解压替换,重启tomcat
@echo off
setlocal enabledelayedexpansion
set TOMCAT_HOME=C:\utils\apache-tomcat-7.0.65
set TOMCAT_PORT=8080
:RESTART
cd %TOMCAT_HOME%\webapps
if exist ROOT.war (
move /y ROOT.war ROOT
cd ROOT
start /wait "" "C:\Program Files\WinRAR\WinRAR.exe" x -y ROOT.war
for /f "delims= tokens=1" %%i in ('netstat -aon ^| findstr "%TOMCAT_PORT%"') do (
set a=%%i
taskkill /pid "!a:~71,5!"
)
)
cd /d %~dp0
netstat -an | find /C "0.0.0.0:%TOMCAT_PORT%" > temp.txt
set /p num=<temp.txt
del /F temp.txt
if %num%==0 (
start /D "%TOMCAT_HOME%\bin\" startup.bat
)
cd /d %~dp0
echo Wscript.Sleep WScript.Arguments(0) >sleep.vbs
cscript //b //nologo sleep.vbs 5000
goto RESTART
来源:oschina
链接:https://my.oschina.net/u/565871/blog/536041