Skip to content

Instantly share code, notes, and snippets.

@ogerardin
Last active May 29, 2024 02:42
Show Gist options
  • Save ogerardin/8f6797186e80e504542680a01594be95 to your computer and use it in GitHub Desktop.
Save ogerardin/8f6797186e80e504542680a01594be95 to your computer and use it in GitHub Desktop.
Extract an Oracle JDK for Windows (up to Java 8) from the EXE file
@echo off
rem
rem Extract an Oracle JDK for Windows (up to Java 8) from the EXE file
rem (c) Olivier Gérardin 2018 ogerardin@yahoo.com
rem Adapted from https://stackoverflow.com/questions/1619662/how-can-i-get-the-latest-jre-jdk-as-a-zip-file-rather-than-exe-or-msi-installe
rem
setlocal EnableDelayedExpansion
set INTERACTIVE=1
echo %CMDCMDLINE% | find /i "%~0" >NUL
if not errorlevel 1 set INTERACTIVE=0
set PATH=%~dp0\bin;%PATH%
if "%~1" == "" (
echo Usage: %~nx0 jdk-*-windows-x64.exe
echo From the Windows Explorer just drop the jdk-*-windows-x64.exe file
echo on the %~nx0 icon.
if "%INTERACTIVE%" == "0" pause
exit /b -1
)
7z >NUL
IF %ERRORLEVEL% neq 0 (
if "%INTERACTIVE%" == "0" pause
exit /b -2
)
set JDK_EXE=%~1
set TARGET=%~dpn1
if exist %TARGET% rmdir /s /q %TARGET%
rem Get tools.zip
7z e %JDK_EXE% .rsrc/1033/JAVA_CAB10/111
7z e 111
del 111
rem Uncompress tools.zip
7z x tools.zip -o%TARGET%
del tools.zip
rem unpack .pack files
for /r jdk %%P in (*.pack) do (
echo %%~nxP
%TARGET%\bin\unpack200 -r "%%P" "%%~dpnP.jar"
)
rem Get src.zip
7z e %JDK_EXE% .rsrc/1033/JAVA_CAB9/110
7z e 110 -o%TARGET%
del 110
endlocal
if "%INTERACTIVE%" == "0" pause
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment