Maven: Fatal error compiling: invalid target release: 1.8

Sometimes this problem is related to a JAVA_HOME used by maven.

  • In my particular case I tried to start an install target and had an exact the subj message.
  • Then I just tried an mvn -version command and I realized that it uses jdk7
  • Then I run in a console set JAVA_HOME=C:\Java\jdk8 (my jdk path, so your own could be different)
  • Then typed mvn clean install test and it worked just fine at last

Good luck!


Check the java and Javac version - My Java version was 1.8.0_51

$ java -version
java version "1.8.0_51"

But javac version was pointing to old jdk 1.7.0_67

$ javac -version
javac 1.7.0_67

There are couple of thing which we should try -

  1. Ensure that symbolic link is pointing to correct jdk. If not, remove existing link and create new one for your jdk

    cd /System/Library/Frameworks/JavaVM.framework/Versions/
    rm CurrentJDK
    ln -s /Library/Java/JavaVirtualMachines/<jdk version>.jdk/Contents/ CurrentJDK
    
  2. In /Library/Java/Extension, i had a tools.jar. I believe, this was from old jdk.

    cd /Library/Java/Extensions
    -rw-r--r--  1 root  admin  15286304 Jan 14  2015 tools.jar
    

    Remove this

    sudo rm -rf /Library/Java/Extensions
    

point 2 did the trick for me :)


Same issue here, but I was using run configurations inside Eclipse when maven kept throwing this error. Fixed by setting the right JDK version here:

Run Configuration image

Tags:

Java

Maven

Java 8