version showing different versions

I have java 7 and java 8 both installed on my windows system under C:Program FilesJava

In the environment's path I specified the path of java 7 like this.

%JAVA_HOME%/bin where JAVA_HOME = C:Program FilesJavajdk1.7.0_17

But when I type javac -version it shows javac 1.7.0_17 which makes sense

but when I do java -version it shows

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

在这里输入图像描述

Any idea what may be the problem here?

Edit The installed folder : 在这里输入图像描述

And one more thing echo %PATH% has only one occurence of JDK that is for java 7 and no occurence for JRE found in it.


The issue is occuring most probably because you have a JRE in your path , before your JDK . This usually happens when we add JDK in the path and do not remove previously added JREs. Thus when you do java it points to the JRE and when you do javac it points to the other version/JDK (since jre does not have a javac in it)

Edit:- Since you edited your question and posted not having any JREs in your path, You can copy your %JAVA_HOME% and paste it first in your path variable (make sure its before system32 path), I have faced this issue before (while installing android sdk) and doing this resolved it.

Also found a possible explanation for this from here :-

JRE also puts a java.exe to c:WindowsSystem32, that's how first command is resolved. Second command is resolved by the C:Program FilesJavajdk1.7.0_02bin entry in your PATH variable. If (and when) you are developing from the command prompt, you have to adjust the PATH variable so that C:Program FilesJavajdk1.7.0_02bin is before c:WindowsSystem32.


Ok, as you said that you have no JRE on your path, I assume that where java (if you have Windows 7) will give you C:WindowsSystem32java.exe .

Changing the java running

Try using the Java-Settings Dialog from the control panel to change the Java System Version, which is currently active. This should change the version java -version is returning. If this does not work, you will probably need to reinstall the Java version of which you want to run the java command, specify the path explicitly, write you own wrapper (which works if you are in the same directory as the wrapper) or place the JRE path before C:WindowsSystem32 onto your path (don't know if last option really is a good one).

A wrapper could look just like this:

@"C:Program FilesJavajre7binjava.exe" %*

and you can either name it java.bat (where it will work if you are in the same directory or put it in PATH before C:WindowsSystem32java.exe or you could name it java7.bat and put it anywhere on you path to be able to run the Java 7 JRE if you desire to do so.

A wrapper is also a good option if you want to change the JAVA_HOME when running.

Changing the javac running

If you want to run a different javac hit Windows + Pause and open the system dialog to change the PATH so it contains the path to your JDK 8 instead of your JDK 7. You will need to restart your command line for changes to show.


To resolve such kind of environment issue I always believe on command whereis, To do the same in windows download whereis.exe then set in path and execute the command

whereis java.exe

whereis javac.exe

You will easily find the exact path from which location java is being called in environment as well about javac.

链接地址: http://www.djcxy.com/p/30270.html

上一篇: 与明暗有关的问题

下一篇: 版本显示不同的版本