20

I am running Windows 7 Professional x64 and have the following Java versions installed:

x64

  • C:\Program Files\Java
    • jdk1.6.0_24
    • jdk1.7.0_04
    • jdk1.7.0_07
    • jre6
    • jre7

x86

  • C:\Program Files (x86)\Java
    • jre1.6.0_07
    • jre6
    • jre7

in my environment variables I have my PATH containing C:\Program Files\Java\jdk1.6.0_24\bin and JAVA_HOME set to C:\Program Files\Java\jdk1.6.0_24\bin

However running java -version reports

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

How is this the case when there is no reference to this version of Java in my Environment variables.

Any help on this issue would be great as I am trying to run Apache ANT using Java 1.6.

Malachi
  • 333
  • 2
  • 5
  • 19

6 Answers6

36

You're probably have java.exe copied over to one of system paths (AFAIK that's Java installer default behavior). To check what actually executes when you run 'java -version' run from command line:
for %I in (java.exe) do @echo %~$PATH:I and it will tell you where it is.

wmz
  • 7,102
  • 1
  • 21
  • 32
  • 2
    Wow - that's so helpful! For some reason `java.exe` is in system32. I will move it it up the path like mentioned. – Malachi Sep 26 '12 at 16:33
  • 1
    Same problem here, `java.exe` was into `system32` AND `ProgramData\Oracle\javapath` – Kevin Labécot Oct 08 '14 at 13:55
  • If you're wondering what to do next, you can rename the `exe`s. I renamed `java.exe`, `javaw.exe` and `javaws.exe` to `java-foobar.exe`, `javaw-foobar.exe` and `javaws-foobar.exe` respectively. – javatarz Dec 09 '14 at 09:22
  • 1
    That increases number of places I need to check to 4: PATH, JAVA_HOME, Control Panels and now also System32... Just wow. One day the registry will become 5th. And to you I thank sir. – Jaroslav Záruba May 07 '17 at 11:29
3

When installing a public JRE (used by the Java plugin), a java.exe file is also created in C:\WINNT\system32 (IIRC). It's probably this java command that is executed, since C:\WINNT\system32 comes before the JDK/bin directory in your PATH.

Put the JDK/bin directory at the beginning of the PATH

Pyuri Sahu
  • 131
  • 1
2

The PATH folders are checked in the order they appear. Try moving the java path to the front. If that fixes the issue then you have another version somewhere on your path.

Chris Nava
  • 7,195
  • 1
  • 27
  • 31
1

This will report the correct java version and it will also clue you in to what the problem is:

@ECHO off
ECHO ---------------
SET "JAVA_HOME=C:\Path to wherever\JDKwhatever"
SET "PATH=%JAVA_HOME%\bin;%PATH%"
java -version
ECHO ---------------
pause
djangofan
  • 2,851
  • 9
  • 34
  • 35
0

I suggest that you uninstall all the JDKs and JREs. Then, you install the latest JDK and you update your classpath, JAVA_HOME and path. This worked for me.

0

As I recently found out, make sure that you're defining JAVA_HOME in the "System variables" section and not the "User variables" section.

I had %JAVA_HOME%\bin at the start of PATH but it wasn't working - adding JAVA_HOME to the system corrected the issue.

Josh
  • 5,143
  • 5
  • 34
  • 44
Paul
  • 11
  • Not sure why people downvoted this, this is also a correct answer, by default you would have `C:\Program Files\Common Files\Oracle\Java\javapath` in the PATH variable of "System Variables", make sure that you are adding `C:\Program Files\Java\jdk-11.0.14\bin` path (change the path as per your installation) to the top of the PATH variable and it will fix the issue – Dharam Mar 08 '22 at 17:09