5
votes

enter image description here

As depicted in above image java home is set and is being echoed but when i check for version it gives me latest version. Already restarted the command prompt after setting env variable. OS is Windows 7

Update:

Following is the Path.

..ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;;%JAVA_HOME%/bin;

5
so, now what is your question? - MWiesner
check your path variable - Sachin Gupta
I remember that java 8 puts a java.exe under Windows\System32. You cannot pretend it doesn't exist. You may have to use the full path of jdk1.6.0, or just uninstall java 8 - cshu

5 Answers

18
votes

I had the same trouble and I solved it with the following steps:

You need the correct Environment Variables.

To be exactly correct only Path variable.

You need to find where you add JAVA_HOME to the path.

Put it at first place at Path variable:

%JAVA_HOME%\bin;...

instead ... all other values of Path.

I assume that JAVA_HOME is defined as a variable and had the correct value.

After this reopen console and check:

java -version

2
votes

JAVA_HOME is environment variable that various application reads in their launcher script

when you invoke java it looks up for all paths specified in your env variable named PATH and wherever the first match is it gets picked up

so if you like command prompt to refer to jdk 6's Java append the path to PATH

0
votes

You need to add the path to jJAVA_HOME%/bin directory in the path variable too. java command is located in %JAVA_HOME%/bin

0
votes

Check your PATH environment variable also. Your system is referring to latest Java installation through PATH variable.

0
votes

I think in your path variable you have hardcoded the path to bin folder. it should always be %JAVA_HOME%/bin.

So that it can pick path from JAVA_HOME variable and you don't need to change both the variables every time.