| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- # 一键重启后端服务脚本
- Write-Host "=========================================" -ForegroundColor Cyan
- Write-Host "后端服务重启脚本" -ForegroundColor Cyan
- Write-Host "=========================================" -ForegroundColor Cyan
- Write-Host ""
- # 1. 停止现有的 Java 进程
- Write-Host "步骤 1: 停止现有的 Java 进程..." -ForegroundColor Yellow
- $javaProcesses = Get-Process | Where-Object {$_.ProcessName -like "*java*"}
- if ($javaProcesses) {
- Write-Host "找到 $($javaProcesses.Count) 个 Java 进程" -ForegroundColor Green
- foreach ($process in $javaProcesses) {
- Write-Host " - 进程 ID: $($process.Id), 启动时间: $($process.StartTime)" -ForegroundColor Gray
- }
-
- $confirm = Read-Host "是否停止这些进程?(Y/N)"
- if ($confirm -eq 'Y' -or $confirm -eq 'y') {
- foreach ($process in $javaProcesses) {
- try {
- Stop-Process -Id $process.Id -Force
- Write-Host " ✓ 已停止进程 $($process.Id)" -ForegroundColor Green
- } catch {
- Write-Host " ✗ 无法停止进程 $($process.Id): $_" -ForegroundColor Red
- }
- }
- } else {
- Write-Host "已取消停止进程" -ForegroundColor Yellow
- exit 0
- }
- } else {
- Write-Host "未找到运行中的 Java 进程" -ForegroundColor Gray
- }
- Write-Host ""
- # 2. 清理并重新编译
- Write-Host "步骤 2: 清理并重新编译项目..." -ForegroundColor Yellow
- Write-Host "执行命令: mvn clean install -DskipTests" -ForegroundColor Gray
- Write-Host ""
- $compileConfirm = Read-Host "是否执行编译?这可能需要几分钟 (Y/N)"
- if ($compileConfirm -eq 'Y' -or $compileConfirm -eq 'y') {
- try {
- mvn clean install -DskipTests
- if ($LASTEXITCODE -eq 0) {
- Write-Host ""
- Write-Host "✓ 编译成功!" -ForegroundColor Green
- } else {
- Write-Host ""
- Write-Host "✗ 编译失败,请检查错误信息" -ForegroundColor Red
- exit 1
- }
- } catch {
- Write-Host "✗ 编译过程出错: $_" -ForegroundColor Red
- exit 1
- }
- } else {
- Write-Host "已跳过编译步骤" -ForegroundColor Yellow
- }
- Write-Host ""
- # 3. 启动后端服务
- Write-Host "步骤 3: 启动后端服务..." -ForegroundColor Yellow
- Write-Host "执行命令: cd yudao-server && mvn spring-boot:run -Dspring-boot.run.profiles=local" -ForegroundColor Gray
- Write-Host ""
- $startConfirm = Read-Host "是否启动后端服务?(Y/N)"
- if ($startConfirm -eq 'Y' -or $startConfirm -eq 'y') {
- Write-Host ""
- Write-Host "正在启动后端服务..." -ForegroundColor Green
- Write-Host "提示: 服务启动后,请访问 http://localhost:48080/doc.html 验证" -ForegroundColor Cyan
- Write-Host ""
-
- Set-Location yudao-server
- mvn spring-boot:run -Dspring-boot.run.profiles=local
- } else {
- Write-Host ""
- Write-Host "已跳过启动步骤" -ForegroundColor Yellow
- Write-Host ""
- Write-Host "手动启动命令:" -ForegroundColor Cyan
- Write-Host " cd yudao-server" -ForegroundColor Gray
- Write-Host " mvn spring-boot:run -Dspring-boot.run.profiles=local" -ForegroundColor Gray
- }
- Write-Host ""
- Write-Host "=========================================" -ForegroundColor Cyan
- Write-Host "完成" -ForegroundColor Cyan
- Write-Host "=========================================" -ForegroundColor Cyan
|