Windows 脚本启动或停止 jar 包
529人浏览 / 0人评论
参考
https://blog.csdn.net/DENG8623048/article/details/127511812
script.bat
@echo off
set operation=%1
set jarName=%2
if "%operation%"=="start" (
echo "Start %jarName% ..."
start javaw -jar %jarName%
echo "Start %jarName% Success..."
jps -l|findStr "%jarName%"
) else if "%operation%"=="stop" (
echo "Stop %jarName%"
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %jarName%`) do (
taskkill /f /pid %%a
)
echo "Stop %jarName% Success..."
) else if "%operation%"=="restart" (
echo "ReStart %jarName% ..."
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %jarName%`) do (
taskkill /f /pid %%a
echo "Restart %jarName% ..."
start javaw -jar %jarName%
jps -l|findStr "%jarName%"
)
echo "Restart %jarName% Success..."
) else if "%operation%"=="status" (
jps -l|findStr "%jarName%"
) else (
echo "Usage: execJar.bat [start|stop|restart|status]"
)
示例
# 启动
script.bat start a.jar
# 停止
script.bat stop a.jar
# 重启
script.bat restart a.jar
# 查看状态
script.bat status a.jar
全部评论