# Windows 下快速部署 SpringBoot 项目的批处理 - 工具 - Windows | ☆∵∴Hito∴∵★ = 涛声依旧 = 天下事有难易乎？为之，则难者亦易矣
Keywords: SpringBoot,Bat,批处理,快速部署

#### # Windows 部署脚本

只需要把 jar 和 yml 跟批处理放在同一目录下即可点击快速启动。启动后再次点击会关闭上次启动的窗口并重新启动。

拷贝以下代码放入 txt 文本，然后改为 start.bat

    @ECHO OFF

    setlocal enabledelayedexpansion

    REM 关闭上次进程

    SET "pidFile=pid.txt"

    if exist "%pidFile%" (

    	for /f "usebackq" %%a in ("pid.txt") do (

    		set PID=%%a

    	)

    	if not "!PID!"=="" (

    		taskkill /F /T /PID !pid!

    		del pid.txt

    	)

    )

    REM 存储当前进程

    for /f %%i in ('wmic process where "name='cmd.exe' and CommandLine like '%%<scriptname>.bat%%'" get ParentProcessId ^| findstr /r "[0-9]"') do set pid=%%i

    echo %PID% > pid.txt

    REM 设置title

    for /f "tokens=2" %%i in ('chcp') do set codepage=%%i

    chcp 65001 > nul

    title 我的SpringBoot项目

    chcp %codepage% > nul

    cd %~dp0

    REM 获取jar

    set "jarFile="

    for %%i in (*.jar) do (

        if not defined jarFile (

            set "jarFile=%%i"

        )

    )

    if not defined jarFile (

        echo not find jar

        pause

        exit

    )

    SET JAVA_OPTS=-Djava.security.egd=file:/dev/./urandom -Dfile.encoding=UTF-8

    set JAVA_OPTS=%JAVA_OPTS% -Dsun.jnu.encoding=UTF8 -Xms512m -Xmx1024m

    set JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5007

    set JAVA_OPTS=%JAVA_OPTS% -Dpid.path=./temp

    REM 获取yml

    set "ymlFile="

    for %%i in (*.yml) do (

        if not defined ymlFile (

            set "ymlFile=%%i"

        )

    )

    if defined ymlFile (

    	set JAVA_OPTS=%JAVA_OPTS% -Dspring.config.additional-location=!ymlFile!

    ) else (

    	echo not find yml

    )

    REM 启动服务

    java %JAVA_OPTS% -jar !jarFile!

    pause

拷贝以下代码放入 txt 文本，然后改为 stop.bat

    @ECHO OFF

    setlocal enabledelayedexpansion

    REM 关闭上次进程

    SET "pidFile=pid.txt"

    if exist "%pidFile%" (

    	for /f "usebackq" %%a in ("pid.txt") do (

    		set PID=%%a

    	)

    	if not "!PID!"=="" (

    		taskkill /F /T /PID !pid!

    		del pid.txt

    	)

    )

    exit

SpringBoot Bat 批处理 快速部署