Skip to content

Instantly share code, notes, and snippets.

@Leo40Git
Last active November 7, 2021 20:33
Show Gist options
  • Save Leo40Git/4ac14732d82c2be6ad2b3f01c4b8aa94 to your computer and use it in GitHub Desktop.
Save Leo40Git/4ac14732d82c2be6ad2b3f01c4b8aa94 to your computer and use it in GitHub Desktop.
Script to create JRE from Maven-style JAR folder
@echo off
setlocal EnableDelayedExpansion
:: these extra dependencies aren't picked up by jdeps
:: jdk.zipfs is required, presumably to access resources embedded in the JAR?
:: jdk.crypto.ec is required for internet communication with SSL
set EXTRA_DEPS=jdk.zipfs,jdk.crypto.ec
set JDK_PATH=%~1
set OUT_PATH=%~2
if exist %OUT_PATH% rmdir /S /Q %OUT_PATH%
echo Enumerating JAR files...
for /r %%a in (*.jar) do (set JARS=!JARS! %%a)
echo Looking for dependencies on modules...
for /f "delims=" %%a in ('"%JDK_PATH%/bin/jdeps.exe" --multi-release 16 --ignore-missing-deps --print-module-deps %JARS%') do (set DEPS=%%a)
echo Generating JRE...
"%JDK_PATH%/bin/jlink.exe" --no-header-files --no-man-pages --strip-debug --compress=0 --add-modules %DEPS%,%EXTRA_DEPS% --output "%OUT_PATH%"
echo Done^^! Enjoy your JRE at "%OUT_PATH%"^^!
pause
endlocal
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment