【JAVA】windows上使用bat腳本後臺啓動,停止和重啓jar包服務

前提:windows上安裝jdk 

1.啓動jar腳本

@echo off
START "app" javaw -jar app-0.0.1-SNAPSHOT.jar

2.停止jar腳本(如:jar包端口9090)

@echo off
set port=9090
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

3.重啓jar腳本(就是上面兩個合起來)

@echo off
set port=9090
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

START "app" javaw -jar app-0.0.1-SNAPSHOT.jar

參考地址:https://www.jianshu.com/p/4e0eea35d3fb

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章