Introduction
Sometimes you want to keep your system clean and avoid installing JDK through the standard exe installer. This is useful when managing multiple JDK versions, working on portable setups, or avoiding registry modifications. The approach below uses 7-zip to extract the JDK files directly.
Prerequisites
- Download the JDK installer from the Oracle website.
- Install 7-zip if it is not already installed.
Steps
- Create an
unpack.batfile in the same folder as the downloaded JDK installer. The script content depends on your 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, passing the installer filename as a parameter:
1
unpack jdk-8u152-windows-x64.exe
or for JDK 9:
1
unpack jdk-9.0.1_windows-x64_bin.exe
Result
After the script completes, you will find an unpacked-jdk directory containing the fully extracted JDK files. You can set JAVA_HOME to this directory and add its bin folder to your PATH to use it.
How It Works
The script performs these operations:
- Extracts the installer archive using 7-zip
- Locates the embedded
tools.zipwithin the installer structure - Extracts
tools.zipto get the JDK files - Runs
unpack200on all.packfiles to convert them to.jarformat (JDK 8 installers use packed jars to reduce download size) - Copies the result to a clean
unpacked-jdkdirectory