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

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

问题描述

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

This morning Maven starts complaining with this error:

错误:-source 1.5不支持multi-catch语句

奇怪的是,我使用的是 JDK 7 并且这段代码已经构建好几个星期了.我只是在没有指定编译器版本的情况下使用带有默认 POM 的 m2e.

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:SDKsJavajdk1.7.0_03jre
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 会生成此错误:“...在 -source 1.5 中不受支持"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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