This procedure uses 7-zip to extract Java from an installation executable and build a portable installation for Windows.
It works for Java Development Kit 1.7 and 1.8 (probably others).
Save the following to a batch file.
@echo off echo Bundled Install Builder for Java 1.7 and 1.8 echo - Creates a bundled installation of Java in the same folder as the provided Java installer file. echo - Ensure you have write permissions to the folder before running this tool. echo - Requires a local installation of 7-zip. echo. set /p zipFile="what is Java executable to extract?" for %%A in ("%zipFile%") do ( set fileName=%%~nA set filePath=%%~pA ) pushd %filePath% :: Not sure what the stucture is so try to extract both files to see what we get. "c:\Program Files\7-Zip\7z" e %zipFile% tools.zip -o"%filePath%" "c:\Program Files\7-Zip\7z" e %zipFile% .rsrc\1033\JAVA_CAB10\111 -o"%filePath%" "c:\Program Files\7-Zip\7z" e 111 tools.zip -o"%filePath%" del /f /q 111 move tools.zip %fileName%.zip "c:\Program Files\7-Zip\7z" x %fileName%.zip -o"%filePath%%fileName%" del /f /q %fileName%.zip pushd "%filePath%%fileName%" for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dpnx.jar" popd popd cls call "%filePath%%fileName%\bin\java.exe" -version echo. echo Move/rename bundled Java "%filePath%%fileName%" as appropriate. echo Point applications to bundled Java with JAVA_HOME environment variable. echo. pause goto :eof :eof @echo on
- Download the desired version of the Java Development Kit (JDK) or Java Runtime Environment) JRE from Oracle's web site.
For example: Google ‘Java download’ or ‘Java SE JDK download’ and look for ‘Java SE Downloads’. This page includes links to the latest two releases of Java. Navigate to the Oracle web site and download the desired Java build (Java 6, 7 or 8) and platform (i586 for 32 bit and x64 for 64 bit.) of the offline installer. Can search for 'Archive' versions too.
- The batch file will take the downloaded Java executable file as input and extract/build a portable Java installation in the same folder as the Java executable.
The batch file needs write access to the location where the Java executable resides.
- Once complete, the packaged Java folder can be renamed and moved to any desired location.
Assuming the Java version is properly reported at the end of the script, close the command prompt and delete the Java executable and any remaining zip files.
- Point desired application to portable Java installation
Set the JAVA_HOME environment variable for the application in question. Typically this is done via the batch file that launches the application. For example:
Depending on the application, it may also necessary to set the PATH environment variable. Ensure the portable Java location is at the beginning of the PATH to override any other Java locations already in the PATH.
set PATH= C:\JDK1.8u121-x64\bin;%PATH%
Now you can move the portable Java folder to any desired location.