为什么Maven会产生此错误:“ - 源1.5不支持...”? [英] Why is Maven generating this error: "...is not supported in -source 1.5"?

查看:242
本文介绍了为什么Maven会产生此错误:“ - 源1.5不支持...”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上Maven开始抱怨这个错误:

This morning Maven starts complaining with this error:

错误:-source 1.5

奇怪的是,我使用的是JDK 7,这段代码已经好几周了。我只是使用m2e和默认的POM,没有指定编译器版本。

Oddly, I'm using JDK 7 and this code has been building fine for weeks. I'm just using m2e with a default POM with no compiler versions specified.

这是我的Maven版本信息:

Here's my Maven version information:

Apache Maven 3.0.2 (r1056850; 2011-01-08 19:58:10-0500)
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: C:\SDKs\Java\jdk1.7.0_03\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

我可以使用像这样的Maven编译器插件来解决它:

I can get around it by using the Maven compiler plugin like so:

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

但是,我想了解为什么Maven突然开始行为不端并要求使用编译器插件。

Still, I'd like to understand why Maven would suddenly start misbehaving and requiring the use of the compiler plugin.

推荐答案

很可能这是您的环境问题,而不是maven(即您的JAVA_HOME环境变量已更改)。值得注意的是,无论如何都需要编译器插件。通过在您的pom中包含此编译器部分,您可以确保使用正确的编译器编译代码,无论您的环境设置如何。

Most likely this is a problem with your environment, not maven (ie, your JAVA_HOME environmental variable changed). It's worth noting that the compiler plugin is required anyway. By including this compiler section in your pom you are ensuring that your code gets compiled with the correct compiler, regardless of your environmental settings.

这篇关于为什么Maven会产生此错误:“ - 源1.5不支持...”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆