javac version and java version show different on command line

試著忘記壹切 提交于 2020-06-28 03:57:30

问题


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.


回答1:


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. 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.



回答2:


In linux distors you can configure java and javac with

update-alternatives --config java
update-alternatives --config javac


来源:https://stackoverflow.com/questions/61644958/javac-version-and-java-version-show-different-on-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!