问题
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:
- If you have put the
PATHas%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%\binin thePATHenvironment 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.
回答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