6

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>
Community
  • 1
  • 1
HappyCoding
  • 5,029
  • 7
  • 31
  • 51
  • 1
    Have you restarted your console after setting you %JAVA_HOME% ?! – Jorge Campos Apr 09 '15 at 02:07
  • Have you run maven -X and looked at the debug trace? Are you sure that Maven is seeing the JAVA_HOME? Have you read http://stackoverflow.com/a/24186685/131433 carefully? – bmargulies Apr 09 '15 at 02:08
  • @JorgeCampos you are right! I need to restart in order for the JAVA_HOME update to take effect! – HappyCoding Apr 09 '15 at 02:19
  • [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 Dec 31 '19 at 18:34

2 Answers2

7

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

Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
  • 1
    Yes. to be more specific, I updated the JAVA_HOME parameter to jdk1.8. But I didn't realize the change has not be taken effect until I check "echo %JAVA_HOME%" in cmd. So always do remember to restart the console or system after updating those parameters. Hope this is also useful for other ppl meeting the same problem in future. – HappyCoding Apr 09 '15 at 02:24
3

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!

  • After I apply all the other suggestions there is still same problem. And then I apply this suggestion for eclipse it works for me – Mustafa Dec 20 '16 at 07:54