@echo off setlocal set targetName=xk-admin set basePath=\opt\server\dist\%targetName% set resourcePath=ff-game\src\main\resources :: 1. 切换到项目根目录(当前脚本所在目录的上两级) cd /d %~dp0 cd .. cd .. :: 2. 可选分支切换(如果提供了参数) if not "%1"=="" ( echo 切换分支: %1 git fetch git checkout %1 ) :: 3. 拉取最新代码 echo 拉取最新代码... git pull :: 4. Maven 构建 echo 开始打包... mvn -Dmaven.test.skip=true clean package if errorlevel 1 ( echo 构建失败,请检查构建日志。 exit /b 1 ) :: 5. 创建目标目录 echo 创建目标目录... mkdir "%basePath%\config" mkdir "%basePath%\dumps" :: 6. 拷贝构建产物 echo 拷贝 JAR 包... for /f %%f in ('dir /b ff-game\target\xk-*.jar') do ( copy "ff-game\target\%%f" "%basePath%\" ) :: 7. 拷贝配置文件 echo 拷贝配置文件... rem Copy all .properties files recursively for /r "%sourcePath%\config" %%f in (*.properties) do ( copy "%%f" "%targetPath%\" ) copy "%sourcePath%\application-prod.properties" "%basePath%\" :: 8. 拷贝启动脚本 echo 拷贝启动脚本... copy ".\start.bat" "%basePath%\" echo 构建并部署完成,路径:%basePath% endlocal pause