start-all.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # PowerShell 脚本:启动拖轮项目的所有服务
  2. Write-Host "==========================================" -ForegroundColor Green
  3. Write-Host " 拖轮项目多服务启动脚本" -ForegroundColor Green
  4. Write-Host "==========================================" -ForegroundColor Green
  5. # 检查Java是否安装
  6. Write-Host "`n检查Java环境..." -ForegroundColor Yellow
  7. try {
  8. $javaVersion = java -version 2>&1
  9. Write-Host "Java 版本: $javaVersion" -ForegroundColor Green
  10. } catch {
  11. Write-Host "错误: 未找到Java环境,请先安装Java" -ForegroundColor Red
  12. exit 1
  13. }
  14. # 检查Node.js是否安装
  15. Write-Host "`n检查Node.js环境..." -ForegroundColor Yellow
  16. try {
  17. $nodeVersion = node --version
  18. $npmVersion = npm --version
  19. Write-Host "Node.js 版本: $nodeVersion" -ForegroundColor Green
  20. Write-Host "NPM 版本: $npmVersion" -ForegroundColor Green
  21. } catch {
  22. Write-Host "错误: 未找到Node.js环境,请先安装Node.js" -ForegroundColor Red
  23. exit 1
  24. }
  25. # 启动认证服务
  26. Write-Host "`n1. 启动认证服务 (端口 8083)..." -ForegroundColor Cyan
  27. Set-Location -Path "$PSScriptRoot\com.lianda.auth"
  28. # 检查Maven是否可用
  29. $mavenAvailable = Get-Command mvn -ErrorAction SilentlyContinue
  30. if ($mavenAvailable) {
  31. Write-Host "使用Maven启动认证服务..." -ForegroundColor Yellow
  32. Start-Process -FilePath "cmd.exe" -ArgumentList "/k", "mvn spring-boot:run"
  33. } else {
  34. Write-Host "Maven不可用,请先安装Maven" -ForegroundColor Red
  35. exit 1
  36. }
  37. # 启动后端服务
  38. Write-Host "`n2. 启动Java后端服务 (端口 8080)..." -ForegroundColor Cyan
  39. Set-Location -Path "$PSScriptRoot\JavaBackend"
  40. if ($mavenAvailable) {
  41. Write-Host "使用Maven启动后端服务..." -ForegroundColor Yellow
  42. Start-Sleep -Seconds 3
  43. Start-Process -FilePath "cmd.exe" -ArgumentList "/k", "mvn spring-boot:run"
  44. } else {
  45. Write-Host "Maven不可用,尝试使用jar包启动..." -ForegroundColor Yellow
  46. # 尝试打包并运行
  47. $buildResult = mvn clean package -DskipTests
  48. if ($buildResult -ne $null) {
  49. # 查找生成的jar文件并启动
  50. $jarFile = Get-ChildItem -Path ".\target" -Filter "*.jar" | Select-Object -First 1
  51. if ($jarFile) {
  52. Write-Host "找到JAR文件: $($jarFile.Name)" -ForegroundColor Green
  53. Start-Sleep -Seconds 3
  54. Start-Process -FilePath "cmd.exe" -ArgumentList "/k", "java -jar $($jarFile.FullName)"
  55. } else {
  56. Write-Host "错误: 未找到可执行的JAR文件" -ForegroundColor Red
  57. }
  58. }
  59. }
  60. # 启动前端服务
  61. Write-Host "`n3. 启动Vue前端服务 (端口 8082)..." -ForegroundColor Cyan
  62. Set-Location -Path "$PSScriptRoot\vue-frontend"
  63. # 安装依赖(如果需要)
  64. if (!(Test-Path -Path "node_modules")) {
  65. Write-Host "安装前端依赖..." -ForegroundColor Yellow
  66. npm install
  67. }
  68. # 启动前端开发服务器
  69. Start-Sleep -Seconds 3
  70. Start-Process -FilePath "cmd.exe" -ArgumentList "/k", "npm run serve"
  71. # 启动数据同步服务
  72. Write-Host "`n4. 启动FlinkDataSync数据同步服务..." -ForegroundColor Cyan
  73. Set-Location -Path "$PSScriptRoot\FlinkDataSync"
  74. if ($mavenAvailable) {
  75. Write-Host "构建FlinkDataSync项目..." -ForegroundColor Yellow
  76. $buildResult = mvn clean package -DskipTests
  77. if ($buildResult -ne $null) {
  78. Write-Host "构建成功,启动数据同步服务..." -ForegroundColor Green
  79. Start-Sleep -Seconds 3
  80. Start-Process -FilePath "cmd.exe" -ArgumentList "/k", "java -cp target\flink-data-sync-1.0-SNAPSHOT.jar com.lianda.flink.sync.MySqlCdcSync"
  81. } else {
  82. Write-Host "错误: 构建FlinkDataSync失败" -ForegroundColor Red
  83. }
  84. } else {
  85. Write-Host "Maven不可用,无法构建FlinkDataSync" -ForegroundColor Red
  86. }
  87. Write-Host "`n==========================================" -ForegroundColor Green
  88. Write-Host "服务启动完成!" -ForegroundColor Green
  89. Write-Host "- 认证服务: http://localhost:8083/auth" -ForegroundColor Green
  90. Write-Host "- 后端服务: http://localhost:8080/api" -ForegroundColor Green
  91. Write-Host "- 前端服务: http://localhost:8082/" -ForegroundColor Green
  92. Write-Host "- 数据同步服务: 运行中(后台)" -ForegroundColor Green
  93. Write-Host "==========================================" -ForegroundColor Green
  94. Write-Host "`n提示: 关闭终端窗口将停止相应的服务" -ForegroundColor Yellow