Tag Archives: Fatal error compiling

[Maven] Fatal error compiling: invalid target release: 1.7 -> [Help 1]

Fatal error compiling: invalid target release: 1.7 -> [Help 1]

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project bugkillers-core: Fatal error compiling: invalid target release: 1.7 -> [Help 1]
[ERROR]

How to Fix
1. mvn -v displays the following results.

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /usr/share/java/apache-maven-3.2.5
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

2. Pom Settings are as follows:

 <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.2</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>

3. But the java-version result is as follows:

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

 

4. 1.7 is not used for compilation, and Maven’s Java Home is set to 1.7 (multiple versions of the JDK are set locally)
Modify maven’s configuration. Java_home points to 1.7,/etc/mavenrc, and ~/.mavenRC. Two files do not exist by default, you need to create, you can choose one
For example: vi ~/.mavenrc
Writing:

JAVA_HOME=`/usr/libexec/java_home -v 1.7`

 

5. Then mVN-V, the results are as follows:

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /usr/share/java/apache-maven-3.2.5
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

Done