run.bat 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. @echo off
  2. chcp 65001 >nul
  3. setlocal EnableDelayedExpansion
  4. set "FRONTEND_DIR=frontend"
  5. set "BACKEND_DIR=backend"
  6. echo ========================================
  7. echo 前后端合并构建部署工具
  8. echo ========================================
  9. echo.
  10. if "%~1"=="build" (
  11. echo [模式] 仅构建(不启动服务)
  12. call :build
  13. echo.
  14. echo [完成] 构建成功!使用 java -jar %BACKEND_DIR%\target\*.jar 运行
  15. goto :eof
  16. )
  17. if "%~1"=="" (
  18. echo [模式] 构建 + 启动
  19. call :build
  20. echo.
  21. echo [启动] 正在启动后端服务...
  22. cd %BACKEND_DIR%
  23. mvn spring-boot:run -q
  24. goto :eof
  25. )
  26. echo [错误] 用法: run.bat (构建+运行)
  27. echo run.bat build (仅构建)
  28. goto :eof
  29. :build
  30. echo ---- [1/3] 前端打包(直接输出到后端 static 目录)----
  31. cd %FRONTEND_DIR%
  32. call npm run build
  33. if errorlevel 1 (
  34. echo [错误] 前端打包失败!
  35. exit /b 1
  36. )
  37. cd ..
  38. echo ---- [2/3] 后端打包 ----
  39. cd %BACKEND_DIR%
  40. call mvn package -DskipTests -q
  41. if errorlevel 1 (
  42. echo [错误] 后端打包失败!
  43. cd ..
  44. exit /b 1
  45. )
  46. cd ..
  47. echo ---- [3/3] 构建完成 ----
  48. goto :eof