49 lines
1.5 KiB
PowerShell
49 lines
1.5 KiB
PowerShell
# 启动后端服务脚本
|
||
Write-Host "正在启动后端服务..." -ForegroundColor Green
|
||
|
||
# 检查jar文件是否存在
|
||
if (-not (Test-Path "target/demo-0.0.1-SNAPSHOT.jar")) {
|
||
Write-Host "错误: jar文件不存在,请先编译项目" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 启动服务
|
||
Write-Host "启动Spring Boot应用..." -ForegroundColor Yellow
|
||
$process = Start-Process -FilePath "java" -ArgumentList "-jar", "target/demo-0.0.1-SNAPSHOT.jar", "--spring.profiles.active=dev" -PassThru -NoNewWindow
|
||
|
||
Write-Host "服务进程ID: $($process.Id)" -ForegroundColor Cyan
|
||
|
||
# 等待服务启动
|
||
Write-Host "等待服务启动..." -ForegroundColor Yellow
|
||
$timeout = 60
|
||
$elapsed = 0
|
||
|
||
while ($elapsed -lt $timeout) {
|
||
Start-Sleep -Seconds 2
|
||
$elapsed += 2
|
||
|
||
# 检查端口是否监听
|
||
$listening = netstat -an | Select-String ":8080.*LISTENING"
|
||
if ($listening) {
|
||
Write-Host "✓ 服务已成功启动在端口8080!" -ForegroundColor Green
|
||
Write-Host "进程ID: $($process.Id)" -ForegroundColor Cyan
|
||
Write-Host "按 Ctrl+C 停止服务" -ForegroundColor Yellow
|
||
|
||
# 保持服务运行
|
||
try {
|
||
$process.WaitForExit()
|
||
} catch {
|
||
Write-Host "服务已停止" -ForegroundColor Red
|
||
}
|
||
break
|
||
}
|
||
|
||
Write-Host "等待中... $elapsed/$timeout 秒" -ForegroundColor Gray
|
||
}
|
||
|
||
if ($elapsed -ge $timeout) {
|
||
Write-Host "✗ 服务启动超时" -ForegroundColor Red
|
||
Stop-Process -Id $process.Id -Force
|
||
exit 1
|
||
}
|