java – Correct installation of Java 8 together with Java 7

The problem is that Java 8 installs a lot of things you don’t really need:

  • \ windows \ system32 contains Java 8 Java.exe, javaw.exe And javaws.exe. Your path probably has system32 near the beginning, so these tend to run by default.

  • The system path variable starts with C: \ programdata \ Oracle \ Java \ javapath. This folder contains Java.exe, javaw.exe And javaws.exe as symbolic links to JRE 8 executables.

I deleted the files system32 and removed C: \ programdata \ Oracle \ Java \ javapath from the system path. This appears to cure the problem. Now I can switch to the versions by indicating Java_HOME And PATH in the appropriate folders.

Apparently, Oracle is determined to make it difficult to run multiple versions. This is understandable with JRE, but crazy with JDK, as developers almost always need multiple versions of Java.

EDIT: I find this batch script useful for changing JDK. Usage: jdk.bat 6 | 7 | 8. You may need to change the installation path for Java.

@echo off
if "%1"=="" goto report
set _version=%1
if "%1"=="DBG" shift & echo on
set _command=%1 %2 %3 %4 %5

set _jdkdir=
set _jdkver=
for /D %%f in ("C:\Program Files\Java\"jdk1.%_version%.*) do call :found "%%f"
if "%_jdkdir%"=="" goto notfound

set Java_home=C:\Program Files\Java\%_jdkdir%
call :javapath
path %new_path%
goto :report

    setlocal enabledelayedexpansion
    set _jdirs=
    for /D %%j in ("C:\Program Files\Java\*") do set _jdirs=!_jdirs!#%%~fj\bin
    set _jdirs=%_jdirs%#

    set _javabin=%Java_home%\bin
    set _fpath="%PATH:;=" "%"
    call :checkpath %_fpath%
    endlocal & set new_path=%_javabin%
goto :eof

    if _%1==_ goto :eof
    echo %_jdirs% | find /i "#%~1#" 1>nul 2>&1
    set _err=%errorlevel%
    if not %_err%==0 set _javabin=%_javabin%;%~1
    if %_err%==0 echo Removed %~1 from path
    goto :checkpath

javac -version
goto :eof

echo No JDK matching [C:\Program Files\Java\jdk1.%_version%.*] found.
goto :eof

set _jdkdir=%~n1%~x1
for /F "tokens=2,3 delims=." %%a in ("%_jdkdir%") do set _jdkver=1.%%a.%%b
goto :eof

Leave a comment