Skip to content

Instantly share code, notes, and snippets.

@der3k
Last active January 7, 2018 23:49
Show Gist options
  • Save der3k/82e489bde7ed5148c1b8 to your computer and use it in GitHub Desktop.
Save der3k/82e489bde7ed5148c1b8 to your computer and use it in GitHub Desktop.
Make JDK portable from EXE installation package
rem based on https://techtavern.wordpress.com/2014/03/25/portable-java-8-sdk-on-windows/
@echo off
rem ******** Configuration ********
set ZIP_EXE=D:\tmp\7zip\App\7-Zip64\7z.exe
rem *******************************
if "%1"=="" goto usage
set JDK_PKG=%~f1
set HOME=%~dp1
set TMP=%HOME%.jdk-tmp\
set JDK_CAB=%TMP%.rsrc\1033\JAVA_CAB10\111
set JDK_TOOLS=%TMP%tools.zip
set JDK_HOME=%~dpn1
echo preparing portable JDK of '%JDK_PKG%'
echo extracting...
"%ZIP_EXE%" x -y -o"%TMP%" "%JDK_PKG%" > NUL
"%ZIP_EXE%" x -y -o"%TMP%" "%JDK_CAB%" > NUL
"%ZIP_EXE%" x -y -o"%JDK_HOME%" "%JDK_TOOLS%" > NUL
echo unpacking...
for /r "%JDK_HOME%" %%i in (*.pack) do "%JDK_HOME%\bin\unpack200.exe" "%%i" "%%~pi%%~ni.jar"
for /r "%JDK_HOME%" %%i in (*.pack) do del "%%i"
echo JDK preprated at '%JDK_HOME%'
exit /b 0
:usage
echo usage: %0 "<jdk-installation.exe>"
exit /b 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment