Maven项目错误:在-source 1.5中不支持钻石/多捕获运算符。

13

由于以下两个错误,我无法构建我的Maven Java Web应用程序:

diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

multi-catch statement is not supported in -source 1.5
  (use -source 7 or higher to enable multi-catch statement)

我有些困惑,因为我在我的项目中使用的是Java 1.8.0,实际上从来没有使用过1.5。

输入图像说明

输入图像说明

可能是什么原因导致了这个问题,我该如何解决?

我尝试在pom.xml中添加以下行后进行构建,但没有成功:

 <properties>
        <sourceJdk>1.8</sourceJdk>
        <targetJdk>1.8</targetJdk>
 </properties>
2个回答

19

尝试在您的pom文件中声明maven-compiler-plugin

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

是的,这个可以工作,但现在我还有一堆其他的错误要解决 ;( - MeesterPatat

2
您也可以通过将以下内容包含在pom.xml中来以这种方式添加它。
 <properties>
   <maven.compiler.source>1.7</maven.compiler.source>
   <maven.compiler.target>1.7</maven.compiler.target>
</properties>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接