2

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.

4
  • Is there a JAVA_HOME environment variable that still points to the JRE of Java 8? Commented May 6, 2020 at 20:40
  • No, it points to Java\jdk-11.0.7 Commented May 6, 2020 at 20:42
  • 1
    It doesn't matter what JAVA_HOME refers to, it only matters what's on the PATH. Apparently you have a JRE on the path before the JDK. To fix, put the JDK first, even before the windows folders. Commented May 6, 2020 at 20:55
  • In my PATH my JDK is at the very top already Commented May 6, 2020 at 21:05

3 Answers 3

2

In linux distors you can configure java and javac with

update-alternatives --config java
update-alternatives --config javac
Sign up to request clarification or add additional context in comments.

1 Comment

I think he asked for Windows platform.
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.

1 Comment

Yes, I had to move System variables path up as well
0

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 \ JavaPath
  • C: \ 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

Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.