javac版本和java版本在命令行上显示不同 [英] javac version and java version show different on command line

查看:68
本文介绍了javac版本和java版本在命令行上显示不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前,我有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:

  1. 如果将PATH设置为%JAVA_HOME%\bin,则如果安装路径(即JAVA_HOME的路径)有空间,则它将不起作用.在这种情况下,您需要在PATH环境变量中放置绝对路径而不是%JAVA_HOME%\bin.
  2. 在新的cmd窗口中尝试命令.
  3. 重新启动系统.
  4. 将JDK bin的路径移至用户变量和系统变量的顶部.
  1. If you have put the PATH as %JAVA_HOME%\bin, it won't work if the installation path (i.e. the path of JAVA_HOME) has space. In such a case, you need to put the absolute path instead of %JAVA_HOME%\bin in the PATH environment variable.
  2. Try the commands in a new cmd window.
  3. Restart the system.
  4. Move the path of JDK bin to the top in both, User variables as well as System variables.

这篇关于javac版本和java版本在命令行上显示不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆