Home » Java » Cannot use Java 7 installation if Java 8 is installed

Cannot use Java 7 installation if Java 8 is installed

Posted by: admin December 28, 2021 Leave a comment


I normally still use Java 7 for all my coding projects (it’s a company “politics” issue), but I installed Java 8 for one third-party project I am contributing to. Now, it seems I cannot have Java 8 installed in Windows 7 x64, and still use Java 7 by default:

C:\>"%JAVA_HOME%\bin\java.exe" -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

C:\>java.exe -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

As you can see, JAVA_HOME is completely ignored.

I also have Java in the path, using “%JAVA_HOME%\bin”, which resolve correctly to Java 7 when I check the path in a DOS box, but it still makes no difference.

I checked in the “Java Control Panel” (not sure if this affects the default command-line Java version). Under the “Java” tab, the “View…” button, you get to see “registered” Java versions. I can add all the versions under the “User” tab, but under “System” there is only Java 8, and no way to change it.

Am I missing something, or did Oracle just make it impossible to use Java 7, unless I de-install Java 8? I don’t want to have to specify the “source” and “target” everywhere, and I don’t even know if it is possible for me to specify it everywhere, where Java is used.

EDIT: What I did is I de-installed all Java. Then installed the latest Java7 (both 86 and x64), and then the latest Java8 (both 86 and x64). After I did that, I noticed that the x64 JDK was gone. It seems Java8 killed it. So I re-installed the JDK 7 x64, after the JDK 8 x64. Still, JDK7 x64 did not seem to “replace” the “java.exe” which is copied into the “Windows” directory itself (I assume THAT is the problem).


When you install jdk8 it adds an entry like this


to beginning of your PATH environment variable, removing this entry should resolve your problem.


You can select the JRE version from the command line with the -version: option.

> java -version:"1.7" MyClass

should select the 1.7 JRE if installed properly.

The list of the properly installed JRE is in the registry, see the key :

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment  (32bit)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment  (64bit)

You can set the “CurrentVersion” there if you want a different default version than the latest.

See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options

Don’t modify your PATH to point to a particuliar JRE, let the special java.exe in Windows/system32 do the job.


Windows and Unix both find programs using their PATH environment variable. You have an java.exe in your Windows\System32 which is appearing before your “preferred” version of Java.

Change the PATH to be the one you need, or specify the full path when you need a different version.


2 Steps


Change registry key **HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion** to point to 1.7


Copy java.exe,javaw.exe and javaws.exe from your java 1.7 version to Windows\System32 folder
(Since the corresponding files of java 1.8 are already there, you might have to overwrite with admin permissions)


(OOps actually not required 3rd step )
Open a new cmd window and check
java -version


Looks like you have to check where in your PATH is located your JAVA_HOME variable, the PATH is evaluated from left to right. A tip for you is to do all your Java system variables configuration at the beginning of your PATH.

PATH = %M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;...

Probably that’s why after doing this:

- java -version

you are getting this:

- java version "1.8.0_05"

because there are other areas in your PATH that are pointing to other java.exe, for example C:\Windows\System32 or C:\ProgramData\Oracle\Java\javapath etc.


I had to make 2 changes for it to work:

  1. Changed the Registry key ‘Software\JavaSoft\Java Runtime Environment’\CurrentVersion’ to 1.7 from 1.8
  2. The Java 8 installation adds a new entry to the PATH environment variable ‘C:\ProgramData\Oracle\Java\javapath’. I removed this entry from the PATH.