0

I have this strange Issue with environment variables on my windows 7 system. Its been there for an year and I have had a work around but I need to solve it now:

I have an environment variable JAVA_HOME set as C:\Program Files\Java\jdk1.6.0_39\. And in my PATH I have added %JAVA_HOME%\bin;.

But when I do java -version it prints "1.7.0_11" and when I do javac -version it prints as expected 1.6.0_39

I do not know why 1.7.0_11 is printed for java -version. I have checked my PATH and have added JAVA_HOME only once. How can I know which env variable is responsible for using my java.exe? How do I avoid it?

2
  • 2
    I understand you mean %JAVA_HOME%\bin, not %JAVA_HOME\bin% Commented Sep 5, 2013 at 14:05
  • 1
    It was a typo. edited it Commented Sep 5, 2013 at 14:17

3 Answers 3

2

It's almost certainly a version of java.exe in c:\Windows\System32, which is likely to come earlier in your path than the part which refers to JAVA_HOME.

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

5 Comments

How would java.exe end up in System32?
@SotiriosDelimanolis: I believe it's just part of the default installation on Windows.
Trying the installer, the default location was C:\Program Files(x86)\Java\jre7 , unless that was the location of a previous installation that the installer found.
Yes it was. But I wonder how did it ever go there. As far as I remember, it should never had happened. Thanks anyways :)
@SotiriosDelimanolis: That's the overall location, but I believe java.exe is also copied into System32 as a matter of course.
1

Ok, hopefully %JAVA_HOME\bin%; is a typo, but if not, it should be %JAVA_HOME%\bin.

For the rest - java -version is looking for your JRE, not your JDK. javac is looking for the JDK.

Check to see if you have a JRE-related environment variable. As well, check your path for any hard references to the Java 7 JRE. Finally, look in C:\Windows\System32 and see if there is a java.exe there.

Comments

1

Java.exe is installed on windows twice. The first location is where you expect it: under your JAVA_HOME. The second one is under c:/windows. Since this path always wins any other user defined path you are running java from here. If you want to hold several java environments and switch between them by changing your JAVA_HOME just remove java.exe from c:/windows.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.