1、在系统环境变量里面查看是否有JAVA_HOME环境变量,如果是用idea来管理环境变量的,需要如图设置指向jbr,如果是单独安装的jdk环境指向自己的安装目录即可
2、设置系统环境Path,需要把jre和bin添加进去
主要是为了编写win下面启动、停止jar包用的
@echo off
rem jar平级目录
set AppName=ent-data-transfer.jar
rem JVM参数
set JVM_OPTS="-Dname=%AppName% -Duser.timezone=Asia/Shanghai -Xms128m -Xmx512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
ECHO.
ECHO. [1] start %AppName%
ECHO. [2] stop %AppName%
ECHO. [3] restart %AppName%
ECHO. [4] status %AppName%
ECHO. [5] quit
ECHO.
ECHO.Please enter the serial number of the selected item:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="4" GOTO status
IF "%id%"=="5" EXIT
ECHO Invalid input. Please try again.
PAUSE
GOTO :EOF
:start
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
set pid=%%a
set image_name=%%b
)
if defined pid (
echo %%is running
PAUSE
)
start javaw %JVM_OPTS% -jar %AppName%
echo starting……
echo Start %AppName% success...
goto:eof
rem 函数stop通过jps命令查找pid并结束进程
:stop
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
set pid=%%a
set image_name=%%b
)
if not defined pid (
echo process %AppName% does not exists
PAUSE
) else (
echo prepare to kill %image_name%
echo start kill %pid% ...
rem 根据进程ID,kill进程
taskkill /f /pid %pid%
PAUSE
)
goto:eof
:restart
call :stop
call :start
goto:eof
:status
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
set pid=%%a
set image_name=%%b
)
if not defined pid (
echo process %AppName% is dead
PAUSE
) else (
echo %image_name% is running
PAUSE
)
goto:eof