param( [string]$Version = "1.2.3", [int]$Port = 18080, [string]$JavaHome = $env:JAVA_HOME ) $ErrorActionPreference = "Stop" $root = Split-Path -Parent $PSScriptRoot $buildRoot = Join-Path $root "build" $jarPath = Join-Path $buildRoot "order-service-demo.jar" $runtimeRoot = Join-Path $root "runtime" $logsRoot = Join-Path $runtimeRoot "logs" $pidFile = Join-Path $runtimeRoot "order-service.pid" $logPath = Join-Path $logsRoot "order-service.log" New-Item -ItemType Directory -Path $logsRoot -Force | Out-Null if (-not (Test-Path $jarPath)) { & (Join-Path $PSScriptRoot "build.ps1") -JavaHome $JavaHome | Out-Null } if (Test-Path $pidFile) { try { $existingPid = Get-Content -LiteralPath $pidFile | Select-Object -First 1 if ($existingPid) { Stop-Process -Id ([int]$existingPid) -Force -ErrorAction SilentlyContinue } } catch {} } $java = if ($JavaHome) { Join-Path $JavaHome "bin\\java.exe" } else { "java" } $arguments = @( "-jar", $jarPath, "--app-name=order-service", "--version=$Version", "--port=$Port", "--log-path=$logPath" ) $process = Start-Process -FilePath $java -ArgumentList $arguments -PassThru -WindowStyle Hidden Set-Content -LiteralPath $pidFile -Value $process.Id -Encoding ASCII Write-Output $process.Id