一、后台运行jar
编辑start.bat:
@echo off
start javaw -Dfile.encoding=utf-8 -jar xxx.jar
echo start success
pause
二、通过端口杀死进程
编辑stop.bat:
@echo off & setlocal EnableDelayedExpansion
title kill port
for %%a in (8080) do (
set pid=0
for /f "tokens=2,5" %%b in ('netstat -ano ^| findstr ":%%a"') do (
set temp=%%b
for /f "usebackq delims=: tokens=1,2" %%i in (`set temp`) do (
if %%j==%%a (
taskkill /f /pid %%c
set pid=%%c
echo The port associated process has been killed
) else (
echo Not native occupant port
)
)
)
if !pid!==0 (
echo The port is not occupied
)
)
echo complete
pause
三、参考
https://blog.csdn.net/u014265785/article/details/105953295/
https://www.jb51.net/article/172169.htm
来源:oschina
链接:https://my.oschina.net/joininjoy/blog/4885862