Skip to content

Instantly share code, notes, and snippets.

@xtman
Created October 22, 2019 05:28
Show Gist options
  • Save xtman/510ed9760484bb95fae0164b9c556990 to your computer and use it in GitHub Desktop.
Save xtman/510ed9760484bb95fae0164b9c556990 to your computer and use it in GitHub Desktop.
A PowerShell Script to build Java Runtime from JDK 11+
if (-Not (Test-Path Env:JAVA_HOME)) {
Write-Output "JAVA_HOME environment variable is not set."
Exit 1
}
$Env:PATH = $Env:JAVA_HOME + "\bin;" + $Env:PATH
$VERSION_LINE = (java -version 2>&1 | Select-String version)
$NAME = ($VERSION_LINE | %{$_.Line.Split(' ')[0];})
$VERSION = ($VERSION_LINE | %{$_.Line.Split(' ')[2].Replace("`"", "");})
$JRE_NAME = $NAME + "-" + $VERSION + "-jre"
$MODULES = ""
java --list-modules | ForEach-Object {
$MODULES += ($_ -replace "@.*") + ","
}
$MODULES = ($MODULES -replace ",$")
Write-Output "Building JRE to directory: .\$JRE_NAME"
jlink --no-header-files --no-man-pages --compress=2 --add-modules ${MODULES} --output ${JRE_NAME}
$WORD_SIZE = (java -version 2>&1 | Select-String Bit | %{$_.Line.Split(' ')[1].Replace("-Bit", "");})
$JRE_ZIP = $JRE_NAME + "_windows-x" + $WORD_SIZE + ".zip"
Write-Output "Making JRE package: .\$JRE_ZIP"
Compress-Archive -Path $JRE_NAME -DestinationPath $JRE_ZIP
Write-Output "Removing diretory: .\$JRE_NAME"
Remove-Item -Recurse -Force -LiteralPath $JRE_NAME
Write-Output "Created JRE package: .\$JRE_ZIP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment