javac 版本和 java 版本在命令行上显示不同 [英] javac version and java version show different on command line
问题描述
之前,我有 java 8.我最近安装了 java 11.我将路径 Javajdk-11.0.7in
移到了环境变量的顶部.当我执行 javac -version
时,它给我版本 11.但是当我执行 java -version
时,它给我版本 8.我该如何解决这个问题?具体来说,我想运行一个使用 java 11 编译的 jar 文件.
Before, I had java 8. I recently installed java 11. I moved my path Javajdk-11.0.7in
to the top of my environment variables. When I do javac -version
it gives me version 11. But when I do java -version
, it gives me version 8. How do I correct this? Specifically, I want to run a jar file that was compiled using java 11.
推荐答案
每当您安装 JDK 时,它也会询问 JRE 的路径.您可能提到了与 JAVA_HOME
不同的 JRE 路径或选择退出安装.如果发生这种情况,您应该卸载 Java 8 和 Java 11,然后再次安装 Java 11.但是,在执行此操作之前,您可以尝试/确保以下事项:
Whenever you install JDK, it asks for the path of JRE as well. There is a possibility that you mentioned a different path for JRE than the JAVA_HOME
or opted out the installation. If that happened, you should uninstall both, Java 8 and Java 11 and then install Java 11 again. However, before you do this, you can try/ensure the following things:
- 如果你把
PATH
设置为%JAVA_HOME%in
,如果安装路径(即JAVA_HOME
的路径)将不起作用代码>) 有空格.在这种情况下,您需要将绝对路径而不是%JAVA_HOME%in
放在PATH
环境变量中. - 在新的 cmd 窗口中尝试这些命令.
- 重新启动系统.
- 将 JDK bin 的路径移到用户变量和系统变量中的顶部.
- If you have put the
PATH
as%JAVA_HOME%in
, it won't work if the installation path (i.e. the path ofJAVA_HOME
) has space. In such a case, you need to put the absolute path instead of%JAVA_HOME%in
in thePATH
environment variable. - Try the commands in a new cmd window.
- Restart the system.
- Move the path of JDK bin to the top in both, User variables as well as System variables.
这篇关于javac 版本和 java 版本在命令行上显示不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!