简体   繁体   English

为什么 Maven 会生成此错误:“...在 -source 1.5 中不受支持”?

[英]Why is Maven generating this error: “…is not supported in -source 1.5”?

This morning Maven starts complaining with this error:今天早上Maven开始抱怨这个错误:

error: multi-catch statement is not supported in -source 1.5

Oddly, I'm using JDK 7 and this code has been building fine for weeks.奇怪的是,我使用的是 JDK 7 并且这段代码已经构建好几个星期了。 I'm just using m2e with a default POM with no compiler versions specified.我只是在没有指定编译器版本的情况下使用带有默认 POM 的 m2e。

Here's my Maven version information:这是我的 Maven 版本信息:

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"

I can get around it by using the Maven compiler plugin like so:我可以通过使用 Maven 编译器插件来解决它,如下所示:

        <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>

Still, I'd like to understand why Maven would suddenly start misbehaving and requiring the use of the compiler plugin.不过,我想了解为什么 Maven 会突然开始行为不端并需要使用编译器插件。

Most likely this is a problem with your environment, not maven (ie, your JAVA_HOME environmental variable changed).这很可能是您的环境问题,而不是 maven(即,您的 JAVA_HOME 环境变量已更改)。 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.通过在 pom 中包含此编译器部分,您可以确保使用正确的编译器编译您的代码,而不管您的环境设置如何。

The default source/target levels are 1.5, which doesn't support Java 1.7 syntax, obviously.默认的源/目标级别是 1.5,这显然不支持 Java 1.7 语法。

As to why it would "suddenly" change, something changed in your m2e or project configuration.至于为什么它会“突然”改变,你的 m2e 或项目配置发生了一些变化。

You can also resolve this problem by using below steps for Eclips user and can be work for IntelliJ as well-您还可以通过为 Eclips 用户使用以下步骤来解决此问题,并且也适用于 IntelliJ -

Right click on the project and select Buid Path then Configure Build Path.. Select Project Facets under Maven.右键单击项目并选择Buid Path 然后Configure Build Path.. 在Maven 下选择Project Facets。 Then select Java version as 1.8 and apply ok.然后选择Java版本为1.8并应用确定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven给出错误:-source 1.5不支持try-with-resources - Maven giving error: try-with-resources is not supported in -source 1.5 Apache Maven:-source 1.5中不支持Diamond运算符 - Apache Maven: Diamond operator is not supported in -source 1.5 行家。 -source 1.5 不支持 lambda 表达式 - maven. lambda expressions are not supported in -source 1.5 为什么我得到错误 diamond operator is not supported in -source 1.5 in Java? - Why i get error diamond operator is not supported in -source 1.5 in Java? Maven问题:-source 1.5 [ERROR]中不支持switch中的字符串(使用-source 7或更高版本来启用switch中的字符串) - Maven Issue: strings in switch are not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable strings in switch) 错误:-source1.5不支持菱形运算符 - error: diamond operator is not supported in -source1.5 使用JRE 1.5,仍然maven说-source 1.3中不支持注释 - Using JRE 1.5, still maven says annotation not supported in -source 1.3 通过Maven错误进行议程代码编译:AgendaSample1Impl.java:[47,81]错误:-source 1.5中不支持Diamond运算符 - Agenda code compilation via maven error: AgendaSample1Impl.java:[47,81] error: diamond operator is not supported in -source 1.5 无法进行Maven构建“在Maven构建中,Eclipse的-source 1.5中不支持switch中的字符串” - Not able maven build “strings in switch are not supported in -source 1.5 in eclipse while maven build” -source 1.5 不支持菱形运算符 - diamond operator is not supported in -source 1.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM