Skip to content

Instantly share code, notes, and snippets.

@milolav
Created April 17, 2017 18:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save milolav/ba9ec81f1fa10077a87f1483b8edb02c to your computer and use it in GitHub Desktop.
Save milolav/ba9ec81f1fa10077a87f1483b8edb02c to your computer and use it in GitHub Desktop.
Batch file to extract portable version of java jre or jdk from installer
@echo off
rem Batch file that extracts java from installer
rem Original topic on stackoverflow:
rem http://stackoverflow.com/questions/1619662/how-can-i-get-the-latest-jre-jdk-as-a-zip-file-rather-than-exe-or-msi-installe
setlocal
if [%1]==[] goto usage
set fn=%~n1
7z.exe e %1 .rsrc\1033\JAVA_CAB10\111
if errorlevel 1 goto err
del %1
7z.exe e 111 tools.zip
if errorlevel 1 goto err
del 111
7z.exe x tools.zip -o%fn%
if errorlevel 1 goto err
del tools.zip
for /r %%i in (*.pack) do (
%fn%\bin\unpack200.exe %%i %%~pi%%~ni.jar
if errorlevel 1 goto err
del %%i
)
echo.
echo All done!
goto end
:usage
echo Usage: %0 ^<JDK/JRE filename^>
echo Note: 7z.exe is required in the folder or in PATH
echo.
echo Example: %0 jdk-8u121-windows-x64.exe
goto end
:err
echo.
echo An error occured, operation aborted
:end
endlocal
@rhodessteve
Copy link

For a version that works with JRE zips the 111 and tools.zip are replaced by Data1.cab and installerexe

@echo off
rem Batch file that extracts java from installer
rem Original topic on stackoverflow:
rem http://stackoverflow.com/questions/1619662/how-can-i-get-the-latest-jre-jdk-as-a-zip-file-rather-than-exe-or-msi-installe

setlocal
if [%1]==[] goto usage
set fn=%~n1
7z.exe e %1 Data1.cab
if errorlevel 1 goto err

del %1
7z.exe e Data1.cab installerexe
if errorlevel 1 goto err

del Data1.cab
7z.exe x installerexe -o%fn%
if errorlevel 1 goto err

del installerexe
for /r %%i in (*.pack) do (
%fn%\bin\unpack200.exe %%i %%~pi%%~ni.jar
if errorlevel 1 goto err
del %%i
)
echo.
echo All done!
goto end

:usage
echo Usage: %0 ^<JDK/JRE filename^>
echo Note: 7z.exe is required in the folder or in PATH
echo.
echo Example: %0 jdk-8u121-windows-x64.exe
goto end

:err
echo.
echo An error occured, operation aborted

:end
endlocal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment