java版本与javac版本,显示不同版本的java -version和javac -version

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

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

%JAVA_HOME%/bin where JAVA_HOME = C:\Program Files\Java\jdk1.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)

jbTFl.jpg

Any idea what may be the problem here?

Edit The installed folder :

XaVdG.jpg

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 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:\Windows\System32, that's how first command is resolved. Second command is resolved by the C:\Program Files\Java\jdk1.7.0_02\bin 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 Files\Java\jdk1.7.0_02\bin is before c:\Windows\System32.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值