How to install Windows JDK without installation

Sometimes we want to keep our system as much clean as possible and do not want to install JDK from exe installer for . Below is a brief instruction on how to do it:

  1. Download JDK from Oracle site – link
  2. Install 7-zip if not already installed
  3. create unpack.bat file at the same folder where JDK from step 1 was downloaded with below content depends on JDK version:
    1. bat file for JDK 8:
      @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"
    2. bat file for JDK 9:
      @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"
  4. start above script from command line with single parameter (name of downloaded JDK exe installer file). For example:
    unpack jdk-8u152-windows-x64.exe

    or

    unpack jdk-9.0.1_windows-x64_bin.exe

Continue reading “How to install Windows JDK without installation”