I have seen similar questions, but haven't yet found the answer.
Using maven compile, I get:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project api: Fatal error compiling: invalid target release: 1.7 -> [Help 1]
Here is the pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Javac version:
javac 1.7.0_25
Java version:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
Any idea what it could be?
You need to set JAVA_HOME to your jdk7 home directory, for example on Microsoft Windows:
or on OS X:
In IntelliJ IDEA this happened to me when I imported a project that had been working fine and running with Java 1.7. I apparently hadn't notified IntelliJ that java 1.7 had been installed on my machine, and it wasn't finding my $JAVA_HOME
.
On a Mac, this is resolved by:
Right clicking on the module | Module Settings | Project
and adding the 1.7 SDK by selecting "New" in the Project SDK.
Then go to the main IntelliJ IDEA menu | Preferences | Maven | Runner
and select the correct JRE. In my case it updated correctly Use Project SDK, which was now 1.7.
When maven is working outside of Eclipse, but giving this error after a JDK change, Go to your Maven Run Configuration, and at the bottom of the Main page, there's a 'Maven Runtime' option. Mine was using the Embedded Maven, so after switching it to use my external maven, it worked.
This probably works for a lot of things but it's not enough for Maven and certainly not for the maven compiler plugin.
Check Mike's answer to his own question here: stackoverflow question 24705877
This solved the issue for me both command line AND within eclipse.
Also, @LinGao answer to stackoverflow question 2503658 and the use of the $JAVACMD variable might help but I haven't tested it myself.
Other than setting JAVA_HOME
environment variable, you got to make sure you are using the correct JDK in your Maven run configuration. Go to Run -> Run Configuration, select your Maven Build configuration, go to JRE tab and set the correct Runtime JRE.
Source: Stackoverflow.com