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.
3 Answers
In linux distors you can configure java and javac with
update-alternatives --config java
update-alternatives --config javac
1 Comment
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.
1 Comment
I had installed JDK16 first, then install JDK1.8. After installing JDK1.8, I automatically updated it once from 1.8.2 to 1.8.3 and then turned off the update function.
First, go to the system environment variable
Move %JAVA_HOME%\bin in PATH to the forefront
Then find two values in PATH:
C: \ Program Files (x86) \ Common Files \ Oracle \ Java \ JavaPathC: \ Program Files \ Common Files \ Oracle \ Java \ JavaPath
One of the directory is also called java.exe file deletion or moves to elsewhere
Then java -version and javac -version will show version 16.0.2.
If we restore the java.exe under "C: \ Program Files (x86) \ Common Files \ Oracle \ Java \ JavaPath Then there will be a case where the version number is inconsistent
2 Comments
JavaPath here, I think it contains symlink files, or is a "junction" folder, more on symlinks in Windows, here
Java\jdk-11.0.7JAVA_HOMErefers to, it only matters what's on thePATH. Apparently you have a JRE on the path before the JDK. To fix, put the JDK first, even before the windows folders.PATHmy JDK is at the very top already