前言
有时候因为程序需要,会启动很多次Tomcat文件,来来回回的关闭、重启比较麻烦
问题解决
下面写了一个程序,命名为rebootTomcat.bat,只需要修改里面的端口号以及Tomcat根路径就可以了,
该程序首先查看端口号是否已经启用,如果启用,则kill掉,然后重新启动tomcat
@echo off & setlocal EnableDelayedExpansion
set obj[0]=Tomcat端口号
set port=0
set pid=0
for /f "usebackq delims== tokens=1-2" %%a in (`set obj`) do (
set port=%%b
for /f "tokens=5" %%m in ('netstat -aon ^| findstr ":%%b"') do (
set pid=%%m
)
if "!pid!"=="0" (
echo the port !port! is released
) else (
taskkill /f /pid !pid!
echo the port !port! is released
)
set pid=0
)
start/d "Tomcat根路径\bin" startup.bat
@echo on