6

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).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85
  • You could change your path environment variable, but you could also remove both versions of Java, install Java 8 first and then Install Java 7 – MadProgrammer May 26 '14 at 21:13
  • What do you use to program and compile? Define your java_home there. – David Brossard May 26 '14 at 21:16
  • I think you missed this bit: "I also have Java in the path, using "%JAVA_HOME%\bin"," Concerning "de/re-installing", I will add what I did in question. – Sebastien Diot May 26 '14 at 21:19
  • @DavidBrossard Neither setting JAVA_HOME, nor the path to java.exe, in the "Windows Environment" has any effect, so I doubt that doing the same within a batch file of Maven or Ant will have a different outcome. – Sebastien Diot May 26 '14 at 21:25

6 Answers6

10

When you install jdk8 it adds an entry like this

C:\ProgramData\Oracle\Java\javapath

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

Jamali
  • 754
  • 10
  • 24
3

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.

RealHowTo
  • 34,977
  • 11
  • 70
  • 85
  • I haven't tried this one, but it sounds like a solution too; it's just that it's less trouble to change the path, then to mess with the registry directly. – Sebastien Diot May 26 '14 at 21:31
  • I know ... but you don't have to mess with the registry if you use the command line option as documented. – RealHowTo May 26 '14 at 21:40
2

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I have the same issue. Can you help me in that ? How did you change the path? Just explain me that what did you do by the line Change the PATH to be the one you need, or specify the full path when you need a different version. – Rushi Jul 23 '15 at 18:42
1

2 Steps

1

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

2

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)

3

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

Community
  • 1
  • 1
Alex
  • 11
  • 1
1

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sergio
  • 11
  • 2
0

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.
A Joshi
  • 151
  • 1
  • 6