JDK - No Install Needed

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:

1jdk-extract path_to_install.exe</pre>

or

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

And now on to the actual the code:

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