InstallJdk.ps1 1.0 KB

123456789101112131415161718192021222324252627
  1. param(
  2. [Parameter(Mandatory = $true)]
  3. $JdkVersion
  4. )
  5. $ErrorActionPreference = 'Stop'
  6. $ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
  7. Set-StrictMode -Version 1
  8. if (-not $env:JAVA_HOME) {
  9. throw 'You must set the JAVA_HOME environment variable to the destination of the JDK.'
  10. }
  11. $repoRoot = Resolve-Path "$PSScriptRoot/../.."
  12. $tempDir = "$repoRoot/obj"
  13. mkdir $tempDir -ea Ignore | out-null
  14. Write-Host "Starting download of JDK ${JdkVersion}"
  15. Invoke-WebRequest -UseBasicParsing -Uri "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" -Out "$tempDir/jdk.zip"
  16. Write-Host "Done downloading JDK ${JdkVersion}"
  17. Expand-Archive "$tempDir/jdk.zip" -d "$tempDir/jdk/"
  18. Write-Host "Expanded JDK to $tempDir"
  19. mkdir (split-path -parent $env:JAVA_HOME) -ea ignore | out-null
  20. Write-Host "Installing JDK to $env:JAVA_HOME"
  21. Move-Item "$tempDir/jdk/jdk-${jdkVersion}" $env:JAVA_HOME
  22. Write-Host "Done installing JDK to $env:JAVA_HOME"