【Maven】Fatal error compiling: invalid target release: 1.7 -> [Help 1] 博客分类: MavenEclipse compiling1.7
程序员文章站
2024-03-24 16:44:58
...
问题: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]
解决:
1、mvn -v 显示结果如下,
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设置如下:
<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、但是java -version 的结果如下:
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,设置maven的java home 为1.7(本机设置了多版本的jdk)
修改maven的配置,java_home指向 1.7 ,/etc/mavenrc 和 ~/.mavenrc。两个文件默认不存在,需要新建,可以任选一个
比如:vi ~/.mavenrc
写入:
JAVA_HOME=`/usr/libexec/java_home -v 1.7`
5、再mvn -v ,结果如下:
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"
6、解决