赞
踩
@echo off rem ================================================================ rem 需要设置好Tomcat的端口号和目录 set TOMCAT_PORT=9003 set CATALINA_HOME=C:\ProgramSoft\tomcat\apache-tomcat-7.0.100-9003 rem ================================================================ echo. echo. echo "======================== bat code ========================" echo. echo. rem 启动脚本文件地址 set STARTUP_BAT=%CATALINA_HOME%\bin\startup.bat rem 停止脚本文件地址 set SHUTDOWN_BAT=%CATALINA_HOME%\bin\shutdown.bat rem 初始化缓存和日志目录(重启服务的时候需要清除缓存和日志) set WORK_DIR=%CATALINA_HOME%\work\Catalina set CONF_DIR=%CATALINA_HOME%\conf\Catalina set LOGS_DIR=%CATALINA_HOME%\logs rem echo.表示是空行,echo和.中间不能有空格 echo. echo. echo "============ environment variable ============" echo [CATALINA_HOME]=%CATALINA_HOME% echo [TOMCAT_PORT]=%TOMCAT_PORT% echo [STARTUP_BAT]=%STARTUP_BAT% echo [SHUTDOWN_BAT]=%SHUTDOWN_BAT% echo "============ environment variable ============" echo. echo. echo "============ cache logs dir ============" echo [WORK_DIR]=%WORK_DIR% echo [CONF_DIR]=%CONF_DIR% echo [LOGS_DIR]=%LOGS_DIR% echo "============ cache logs dir ============" rem 休眠5秒 echo. echo. ping -n 5 127.0.0.1 rem 调用停止脚本来停掉服务. echo "============ shutdown server ============" echo. echo. call %SHUTDOWN_BAT% echo %CATALINA_HOME% is killed ... rem 由于服务没有完全关闭(服务停了,但是窗口没有关闭,因此通过监听端口号并杀死进程来关闭窗口). echo. echo. for /f "tokens=5" %%a in ('netstat /ano ^| findstr %TOMCAT_PORT%') do taskkill /F /pid %%a echo. echo. echo "============ shutdown server ============" rem 清除缓存和日志文件. ping -n 3 127.0.0.1 echo. echo. echo "============ clear Catalina-work ============" rmdir /s/q %WORK_DIR% echo "============ clear Catalina-work ============" ping -n 3 127.0.0.1 echo. echo. echo "============ clear Catalina-conf ============" rmdir /s/q %CONF_DIR% echo "============ clear Catalina-conf ============" ping -n 3 127.0.0.1 echo. echo. echo "============ clear logs ============" del /s/q/f %LOGS_DIR% echo "============ clear logs ============" echo. echo. ping -n 5 127.0.0.1 rem 调用启动脚本. echo "============ start server ============" echo. echo. call %STARTUP_BAT% echo %CATALINA_HOME% is started ... echo. echo. echo "============ start server ============" ping -n 5 127.0.0.1
使用说明:
第一种:直接双击restart.bat文件。
第二种:
(1)win+R
(2)切换目录到restart.bat文件所在目录。
(3)在命令窗口输入restart.bat,回车即可。
区别:第一种执行结束后,restart.bat窗口会关闭(不是tomcat窗口),第二种restart.bat窗口不会关闭,方便查看运行日志。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。