If you have installed Java through brew
in Mac
then chances are you will find your Java Home Directory here:
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
The next step now would be to find which Java Home
directory maven is pointing to. To find it type in the command:
mvn -version
The fields we are interested in here is:
Java version
and runtime
.
Maven is currently pointing to Java 13
. Also, you can see the Java Home path under the key runtime, which is:
/usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
To change the Java version of the maven, we need to add the Java 8
home path to the JAVA_HOME
env variable.
To do that we need to run the command:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
in the terminal.
Now if we check the maven version, we can see that it is pointing to Java 8 now.
The problem with this is if you check the maven version again in the new terminal, you will find that it is pointing to the Java 13. To avoid this I would suggest adding the JAVA_HOME
variable in the ~/.profile
file.
This way whenever your terminal is loading it will take up the value you defined in the JAVA_HOME by default. This is the line you need to add in the ~/.profile
file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
You can open up a new terminal and check the Maven version, (mvn -version
) and you will find it is pointing to the Java 8 this time.