windows运行jar项目的bat命令

菠萝饭 60 2021-11-24

最近用到了,现做简单总结:

启动
@echo off
%1 mshta vbscript:CreateObject("WScript.Shell").Run("%~s0 ::",0,FALSE)(window.close)&&exit
java -jar -Dfile.encoding=utf-8 eladmin-system-2.6.jar  >StartupLog.log  2>&1 &
exit

停止
@echo off
set port=8000
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
    echo kill the process %%m who use the port 
    taskkill /pid %%m -t -f
    goto q
)
:q
重启
@echo off
set port=8000
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
    echo kill the process %%m who use the port 
    taskkill /pid %%m -t -f
    goto start
)
:start
 
%1 mshta vbscript:CreateObject("WScript.Shell").Run("%~s0 ::",0,FALSE)(window.close)&&exit
java -jar -Dfile.encoding=utf-8 eladmin-system-2.6.jar  >StartupLog.log  2>&1 &
exit


# 实际问题