I don’t like the whole concept of installers for my development tools like JDK, Eclipse, Netbeans, etc. I just keep a batch/shell script to setup my environment variables for JAVA_HOME, PATH and aliases.

So, on Windows, updating JDK involves installing new version of JDK and then copying what I need and then uninstall it. I don’t like those registry entries and files installed in C:\Windows\System32, etc.

Recently I read a stackoverflow entry that gave some insight on JDK packaging. So I wrote a small batch script to do it all. Only quirk is that, there is a small difference in Pre 7.0 packaging from the 7.0 and above, so for now I need to keep 2 scripts. Scripts need 7z, that is a free tool and could be downloaded from here.

These scripts can be run as:

1
jdk-extract path_to_install.exe</pre>

or

1
jdk-extract-pre-7.0.bat path_to_installer.bat

And now on to the actual the code:

jdk-extract.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@echo off
REM This script will extract JDK tools from installers, without polluting Windows environment.
REM You need the pristine installers from Oracles website to extract all the data
setlocal
SET CWD=%CD%
SET FILE=%~f1
SET DEST=%~dpn1
echo DEST=%DEST% FILE=%FILE% CWD=%CWD%
md %DEST%
REM Used e here instead of x to keep structure flat
7z e -o"%DEST%" -y "%FILE%" tools.zip
cd "%DEST%"
7z x -y tools.zip
del tools.zip
for /r %%x in (*.pack) do call :unpack2000 "%%x"
cd %CWD%
goto end
:unpack2000
%DEST%\bin\unpack200 -r %1 "%~dpn1.jar"
goto:eof
:end
echo Extracted %FILE% to %DEST%
jdk-extract-pre-7.0.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@echo off
REM This script will extract JDK tools from installers, without polluting Windows environment.
REM You need the pristine installers from Oracles website to extract all the data
setlocal
SET CWD=%CD%
SET FILE=%~f1
SET DEST=%~dpn1
echo DEST=%DEST% FILE=%FILE% CWD=%CWD%
md %DEST%
REM Used e here instead of x to keep structure flat
7z e -o"%DEST%" -y "%FILE%" .rsrc\JAVA_CAB10\111
cd "%DEST%"
extrac32.exe 111
del 111
7z x -y tools.zip
del tools.zip
for /r %%x in (*.pack) do call :unpack2000 "%%x"
cd %CWD%
goto end
:unpack2000
%DEST%\bin\unpack200 -r %1 "%~dpn1.jar"
goto:eof
:end
echo Extracted %FILE% to %DEST%