Maven项目安装:目标版本无效:1.7错误

时间:2015-11-03 12:55:30

标签: java maven

当我尝试使用maven安装项目时出现此错误。 我读了很多帖子说这个错误是因为maven正在使用另一个版本的java但是这不是我的情况(我认为),因为我运行的每个命令都说使用的版本是java 1.7。

这是终端的结果:

Maven installation error:
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options

mvn -version的输出

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 12:22:22-0300)
Maven home: /Applications/Dev/apache-maven-3.3.3
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.11.1", arch: "x86_64", family: "mac"

Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

pom.xml(编译器插件部分):

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

一切看起来都不错,但一直都是错误。

1 个答案:

答案 0 :(得分:2)

maven-compiler-plugin版本更新为 3.3

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version> <!--  HERE  -->
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

JAVA_HOME如何设定?

  

Java home:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre

您需要将此更正为/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/

Why I am not able to see the JAVA_HOME path on my MAC OS X 10.11?