Skip to content

Instantly share code, notes, and snippets.

@pexcn
Forked from milolav/java_extract.bat
Created September 5, 2018 13:31
Show Gist options
  • Save pexcn/c82f0a00c0c5e3d028d6202a5bc7c0f4 to your computer and use it in GitHub Desktop.
Save pexcn/c82f0a00c0c5e3d028d6202a5bc7c0f4 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment