java -version and javac -version showing different versions

后端 未结 9 1842
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 01:29

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

In the environment\'s path I specif

相关标签:
9条回答
  • 2020-12-03 01:51

    Please check that you have replaced "C:\ProgramData\Oracle\Java\javapath;" with %JAVA_HOME%/bin in the PATH variable. This did the trick for me.

    0 讨论(0)
  • 2020-12-03 01:52

    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)
  • 2020-12-03 01:56

    I guess when you are writing javac, it is getting the value from jre7 which is currently being used by you for development purposes and when you write java version, it is getting the value of the version from the jre8 which is currently being used by the installed applications on your system because your JRE of the system is mentioned before the jre7 which you are using for development

    0 讨论(0)
提交回复
热议问题