53 lines
1.9 KiB
PowerShell
53 lines
1.9 KiB
PowerShell
# Install Microsoft JDK 17 from pre-uploaded zip (no internet required)
|
|
$ErrorActionPreference = "Stop"
|
|
$Tools = "E:\wwwroot\tools"
|
|
$Zip = "C:\Users\ytd_extdev_0903\incoming\microsoft-jdk-17-windows-x64.zip"
|
|
$Dest = Join-Path $Tools "jdk-17"
|
|
|
|
if (-not (Test-Path $Zip)) { throw "missing $Zip" }
|
|
New-Item -ItemType Directory -Force -Path $Tools | Out-Null
|
|
|
|
Write-Output ("ZIP_BYTES=" + (Get-Item $Zip).Length)
|
|
if (Test-Path $Dest) {
|
|
Rename-Item $Dest ("jdk-17.bak-" + (Get-Date -Format "yyyyMMddHHmmss"))
|
|
}
|
|
|
|
$stage = Join-Path $Tools ("jdk17-stage-" + (Get-Date -Format "yyyyMMddHHmmss"))
|
|
New-Item -ItemType Directory -Force -Path $stage | Out-Null
|
|
Write-Output "=== expand ==="
|
|
Expand-Archive -Path $Zip -DestinationPath $stage -Force
|
|
$jdkRoot = Get-ChildItem $stage -Directory | Select-Object -First 1
|
|
if (-not $jdkRoot) { throw "no jdk root in zip" }
|
|
Move-Item $jdkRoot.FullName $Dest
|
|
Remove-Item $stage -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
$java = Join-Path $Dest "bin\java.exe"
|
|
if (-not (Test-Path $java)) { throw "java.exe missing at $java" }
|
|
& $java -version 2>&1 | ForEach-Object { "$_" }
|
|
|
|
[Environment]::SetEnvironmentVariable("JDK17_HOME", $Dest, "Machine")
|
|
[Environment]::SetEnvironmentVariable("JAVA17_HOME", $Dest, "Machine")
|
|
|
|
$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 = "Microsoft OpenJDK"
|
|
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
|
|
New-Item -ItemType Directory -Force -Path "E:\wwwroot\ops" | Out-Null
|
|
Set-Content -Path "E:\wwwroot\ops\jdk17.json" -Value $info -Encoding UTF8
|
|
|
|
Write-Output "JDK17_HOME=$Dest"
|
|
Write-Output "INSTALL_OK"
|