Sometimes we want to keep our system as clean as possible and avoid installing JDK from the exe installer. Here is a brief how-to:
Steps
-
Download JDK from the Oracle website
-
Install 7-zip if not already installed
-
Create an
unpack.batfile in the same folder as the downloaded JDK installer, with content depending on the JDK version:
Batch file for JDK 8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@echo off
set PATH=%PATH%;C:\Program Files\7-Zip\
rmdir /s /q "%~dp0\jdk-out"
rmdir /s /q "%~dp0\unpacked-jdk"
7z x %1 -o"%~dp0\jdk-out"
cd /d "jdk-out\.rsrc\1033\JAVA_CAB10"
extrac32 111
7z x tools.zip -ojdk
cd /d "jdk"
for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dx%%~px%%~nx.jar"
mkdir "%~dp0\unpacked-jdk"
xcopy /s "%~dp0\jdk-out\.rsrc\1033\JAVA_CAB10\jdk" "%~dp0\unpacked-jdk"
cd /d "%~dp0"
cd /d "jdk-out\.rsrc\1033\JAVA_CAB9"
extrac32 110
xcopy /s "%~dp0\jdk-out\.rsrc\1033\JAVA_CAB9\src.zip" "%~dp0\unpacked-jdk"
cd /d "%~dp0"
rmdir /s /q "%~dp0\jdk-out"
Batch file for JDK 9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@echo off
set PATH=%PATH%;C:\Program Files\7-Zip\
rmdir /s /q "%~dp0\jdk-out"
rmdir /s /q "%~dp0\unpacked-jdk"
7z x %1 -o"%~dp0\jdk-out"
cd /d "jdk-out"
7z x tools.zip -ojdk
cd /d "jdk"
for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dx%%~px%%~nx.jar"
mkdir "%~dp0\unpacked-jdk"
xcopy /s "%~dp0\jdk-out\jdk" "%~dp0\unpacked-jdk"
cd /d "%~dp0"
rmdir /s /q "%~dp0\jdk-out"
- Run the script from the command line with the installer filename as the parameter:
1
unpack jdk-8u152-windows-x64.exe
or
1
unpack jdk-9.0.1_windows-x64_bin.exe
After completing these steps, you will find an unpacked-jdk directory containing the extracted JDK files.