Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java -version and javac -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)

enter image description here

Any idea what may be the problem here?

Edit The installed folder : enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 the JRE does not have a javac in it)

If you don't have any JREs in your path, then you can copy your %JAVA_HOME% and paste it first in your path variable (make sure its before the system32 path).

A possible reason for why this works is explained in this answer:

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_02in 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_02in is before c:WindowsSystem32.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...