When we need to install JDK 12 to utilize some new features in Java 12, we will encounter some problems that are related to multiple versions of JDK.
Now, in this article, we will fix them. Let’s go.
Table of contents
- The problem’s context
- Solution for this problem
- Use batch file to setup environment variable
- Remove old JDK, JRE version, setup JDK and JRE 12 in Eclipse
- Wrapping up
The problem’s context
In our computer, we installed the JDK 8, but now we also want to install JDK 12. After downloading and installing completely, in Eclipse, we find that eclipse does not realize the syntaxes in Java 12.
So, when we type command in CMD, we have:
java -version javac -version
–> Result: Version of java: 1.8.191 and version of javac: 12.0.1
Two above version is not the same.
Solution for this problem
The first thing that we need to do is to set environment variable
JAVA_HOMEto our directory of JDK version 12.
The second thing is that we need to look at the
C:\Program Files (x86)\Common Files\Oracle\Java\javapathin Windows 8 or
C:\ProgramData\Oracle\Java\javapathin Windows 10 is at the first in
PATH. So, we need to change
%JAVA_HOME%\binthat is at the first in
Use batch file to setup environment variable
@echo off echo Setting JAVA_HOME set JAVA_HOME=C:\Program Files\Java\jdk-12.0.1 echo setting PATH set PATH=C:\Program Files\Java\jdk-12.0.1\bin;%PATH% echo Display java version java -version
Remove old JDK version, setup JDK and JRE 12 in Eclipse
Window/Preferences, jump to
Java/Installed JREs, add the path of JDK 12:
Project/Properties, look at
Java Build Path–>
- Understanding about some parts in JDK, JRE.
- Use command line to setup environment variables.