# Install Temurin JDK 17 portable under E:\wwwroot\tools (do not replace jdk8) $ErrorActionPreference = "Stop" $Tools = "E:\wwwroot\tools" $Zip = Join-Path $Tools "OpenJDK17-windows-x64.zip" $Dest = Join-Path $Tools "jdk-17" $Url = "https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk" New-Item -ItemType Directory -Force -Path $Tools | Out-Null if (-not (Test-Path (Join-Path $Dest "bin\java.exe"))) { Write-Output "=== download ===" if (Test-Path $Zip) { Remove-Item $Zip -Force } # TLS [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $ProgressPreference = "SilentlyContinue" Invoke-WebRequest -Uri $Url -OutFile $Zip -UseBasicParsing -TimeoutSec 600 Write-Output ("ZIP_BYTES=" + (Get-Item $Zip).Length) Write-Output "=== expand ===" $stage = Join-Path $Tools ("jdk17-stage-" + (Get-Date -Format "yyyyMMddHHmmss")) New-Item -ItemType Directory -Force -Path $stage | Out-Null Expand-Archive -Path $Zip -DestinationPath $stage -Force $jdkRoot = Get-ChildItem $stage -Directory | Select-Object -First 1 if (-not $jdkRoot) { throw "no jdk folder in zip" } if (Test-Path $Dest) { Remove-Item $Dest -Recurse -Force } Move-Item $jdkRoot.FullName $Dest Remove-Item $stage -Recurse -Force -ErrorAction SilentlyContinue Remove-Item $Zip -Force -ErrorAction SilentlyContinue } else { Write-Output "JDK_ALREADY_PRESENT" } $java = Join-Path $Dest "bin\java.exe" if (-not (Test-Path $java)) { throw "java.exe missing" } & $java -version 2>&1 | ForEach-Object { "$_" } # Machine-level JDK17_HOME for new ledger; do NOT overwrite JAVA_HOME if jdk8 services rely on it [Environment]::SetEnvironmentVariable("JDK17_HOME", $Dest, "Machine") [Environment]::SetEnvironmentVariable("JAVA17_HOME", $Dest, "Machine") # Write helper for ops $cmd = @" @echo off REM New-system JDK17 only. Do not use for legacy Jeecg (jdk8). set JAVA_HOME=$Dest set PATH=%JAVA_HOME%\bin;%PATH% "@ Set-Content -Path (Join-Path $Tools "use-jdk17.cmd") -Value $cmd -Encoding ASCII $info = @{ vendor = "Eclipse Temurin" major = 17 home = $Dest javaExe = $java installedAt = (Get-Date).ToString("o") note = "Alongside C:\yutongda\tools\jdk8; legacy JAVA_HOME untouched" } | ConvertTo-Json Set-Content -Path (Join-Path $Tools "jdk17.json") -Value $info -Encoding UTF8 Set-Content -Path "E:\wwwroot\ops\jdk17.json" -Value $info -Encoding UTF8 Write-Output "JDK17_HOME=$Dest" Write-Output "INSTALL_OK"