javac版本和java版本在命令行上显示不同 [英] javac version and java version show different on command line
问题描述
之前,我有Java8.最近安装了Java11.我将路径Java\jdk-11.0.7\bin
移到了环境变量的顶部.当我执行javac -version
时,它会给我版本11.但是当我执行java -version
时,它会给我版本8.我该如何纠正?具体来说,我想运行一个使用Java 11编译的jar文件.
Before, I had java 8. I recently installed java 11. I moved my path Java\jdk-11.0.7\bin
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的路径.您提到的JRE路径可能不同于JAVA_HOME
,或者选择退出安装.如果发生这种情况,则应同时卸载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%\bin
,则如果安装路径(即JAVA_HOME
的路径)有空间,则它将不起作用.在这种情况下,您需要在PATH
环境变量中放置绝对路径而不是%JAVA_HOME%\bin
. - 在新的cmd窗口中尝试命令.
- 重新启动系统.
- 将JDK bin的路径移至用户变量和系统变量的顶部.
- If you have put the
PATH
as%JAVA_HOME%\bin
, 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%\bin
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屋!