How to fix Fatal error compiling: invalid target release: 1.8

H

This tutorial is writen for mac users, on windows I didn’t have this error.

When I tried to do a mvn compile. I got the following error:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile
(default-compile) on project ...: Fatal error compiling: invalid target release: 1.8

You will get this error because you asked maven to compile in a higher JDK then your current JDK is. To see what your current JDK is, type the following command in your terminal:

ls -alh /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

When I typed this command, I got the following result:

/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ->
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

What, 1.6? But if I run java -version, I got 1.8… Now, to fix this, open a second terminal. There you type the following commands:

cd /Library/Java/JavaVirtualMachines/
ls

After I did that, my result was:

jdk1.7.0_71.jdk	jdk1.8.0_25.jdk

I want jdk1.8.0_25.jdk to be my current JDK, so I changed the current JDK by the following command:

sudo ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents CurrentJDK

If you copy/paste this code, don’t forget to change the JDK version to yours! Now If you run the code below again, you will notice that 1.8 is your current JDK now.

ls -alh /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Try a mvn compile again and enjoy 😀

2 comments

Leave a Reply to Neer Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Shouldn’t the command to set the symlink be
    `sudo ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK`

  • Thank you. This solution works. Also, the ‘CurrentJDK’ softlink in the last step was incorrect and Neer corrected it.

    Thank you both for the solution!

Tag Cloud

Categories

%d bloggers like this: