Skip to content

Instantly share code, notes, and snippets.

@wbminsssss
Last active December 29, 2024 08:17
Show Gist options
  • Select an option

  • Save wbminsssss/345359da2b352310b7d5c31afd609310 to your computer and use it in GitHub Desktop.

Select an option

Save wbminsssss/345359da2b352310b7d5c31afd609310 to your computer and use it in GitHub Desktop.
从exe文件中提取用于Windows (Java 8以下)的Oracle JDK
@echo off
rem
rem Extract an Oracle JDK for Windows (up to Java 8) from the EXE file
rem (c) Olivier Gérardin 2018 [email protected]
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 在这个脚本基础上修改 https://gist.github.com/ogerardin/8f6797186e80e504542680a01594be95
rem 在 AI(gemini-1.5-pro-latest) 和我的努力下完成
rem 新建一个文件夹,里面应该包含 7z.exe、jdk-*-windows-x64.exe、extractjdk.bat(内容为当前脚本),将exe文件拖拽用这个脚本打开
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" -o%TARGET%
7z e %TARGET%\111 -o%TARGET%
rem uncompress tools.zip
7z x %TARGET%\tools.zip -o%TARGET%
rem unpack .pack files
for /r %%x in (*.pack) do (
"%TARGET%\bin\unpack200" "%%x" "%%~dpx%%~nx.jar"
)
rem get src.zip
7z e %JDK_EXE% ".rsrc\1033\JAVA_CAB9\110" -o%TARGET%
7z e %TARGET%\110 -o%TARGET%
rem del temp file
del /q %TARGET%\111 %TARGET%\tools.zip %TARGET%\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