3

I am really frustrated to see following behavior and not sure yet after research how to fixed this. I've two separate projects one works only on Java 7 (can't update to Java 8) and another project works on Java 8 (can't downgrade to 7). So I've both Java 7 and 8 installed on my windows machine.

So, I am seeing following behavior constantly. Currently I am on Java 8 and would like switch back Java 7, so I changed environment variable JAVA_HOME and PATH to point to Java 7, but when I verify through CMD, it shows me following.

C:\>java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

C:\>javac -version
javac 1.7.0_71

I can't use above combination, neither projects works for me. So I always need to uninstalled Java 8 and then only I can point to Java 7. Also if I want to move back to Java 8 (again installed Java 8), then it shows me following combination. How to fixed this error on Windows? As uninstalling the JDK every time is not the solution. Please help me.

C:\>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

C:\>javac -version
javac 1.8.0_45

1 Answer 1

6

java.exe, the Java runtime, also installs in c:\windows or c:\windows\system32 (can't remember, I'm on a Mac now).

So even if your PATH contains the bin directory of JDK, if c:\windows (or c:\windows\system32) comes before JDK\bin in the PATH, the version in c:\windows (or c:\windows\system32) is the one that is used.

Just make sure the JDK is first in the PATH, or at least before c:\windows (or c:\windows\system32).

Sign up to request clarification or add additional context in comments.

3 Comments

Have you restarted cmd.exe after making this change? Because that's not taken into account in existing cmd.exe instances. Also, what is C:\ProgramData\Oracle\Java\javapath?
Lately I've seen links in C:\ProgramData\Oracle\Java\javapath and that dir added to path. I can no longer find java.exe in any windows dir. Also it's 64 bit so I don't think it would be in sys32.
JBNizet provided the right answer. @User4567570: Setting JAVA_HOME env. variable to the path of the JDK (e.g. c:\java\jdk8u60) to use is the only things to update, if the PATH env. variable itself is set with %JAVA_HOME%\bin, and if its position is located before the declaration of system32. The console need to be restarted for the environment variables to take effect. The discrepency between javac -version and java -version means that both location are defined, for each JDK, in the path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.