一、创建start.bat文件

二、以文本编辑打开文件,编辑如下命令

@echo off
%1 mshta vbscript:CreateObject("WScript.Shell").Run("%~s0 ::",0,FALSE)(window.close)&&exit
java -jar xxx.jar > log.log 2>&1 &
exit

三、如果要指定配置文件,配置Jvm 环境,则编辑如下命令

@echo off
%1 mshta vbscript:CreateObject("WScript.Shell").Run("%~s0 ::",0,FALSE)(window.close)&&exit
set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
java -jar xxx.jar  --spring.config.location=./conf/application.yml  >  log.log 2>&1 &
exit

四、创建stop.bat 关闭特定端口的java程序

@echo off
set port=xxx(项目端口号)
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do taskkill /f /pid %%m

五、创建restart.bat ,重启jar包

@echo off
%1 mshta vbscript:CreateObject("WScript.Shell").Run("%~s0 ::",0,FALSE)(window.close)&&exit
set port=xxx(项目端口号)
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do taskkill /f /pid %%m &
set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
java -jar xxx.jar  --spring.config.location=./conf/application.yml  >  log.log 2>&1 &
exit

原文地址:https://blog.csdn.net/Crazy_Cw/article/details/125690560

最后修改:2022 年 11 月 28 日
請我飲咖啡