6
votes

Similar problem as posted in Fatal error compiling: invalid target release: 1.8 -> [Help 1] However, problem is not solved after I check my settings with the solutions. Details is as follows.

Maven Error Message is:

[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 -> [Help 1]

My JAVA_HOME setting is:

C:\Program Files\Java\jdk1.8.0_40

Java -version:

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

I've added compilation detail to pom.

  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
2
Have you restarted your console after setting you %JAVA_HOME% ?! - Jorge Campos
Have you run maven -X and looked at the debug trace? Are you sure that Maven is seeing the JAVA_HOME? Have you read stackoverflow.com/a/24186685/131433 carefully? - bmargulies
@JorgeCampos you are right! I need to restart in order for the JAVA_HOME update to take effect! - HappyCoding
[on Windows machine] Check PATH and JAVA_HOME environment variables if it is. Make sure they point to the same jdk version as provided in pom.xml as source and target version in maven compiler plugin section. Correct variables if mismatched. You may need to restart your machine to get this change reflected and then mvn compile, it will fix the issue for sure. - Pratap Singh

2 Answers

7
votes

As discussed in comments, You need to restart your console after setting your %JAVA_HOME% enviroment variable.

3
votes

Eclipse Users, Cross check your run configuration in Maven build. Follow steps to correct -

  1. "Run Configuration"
  2. Under "Maven Build", Select configuration you are using
  3. Click on "JRE" tab
  4. Select Correct JAVA Version

This solution works for me!