【问题标题】:Maven project Error: Diamond/multicatch operator not supported in -source 1.5 [duplicate]Maven 项目错误:-source 1.5 中不支持 Diamond/multicatch 运算符 [重复]
【发布时间】:2014-11-12 18:40:38
【问题描述】:

由于以下两个错误,我无法构建我的 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>

【问题讨论】:

    标签: java maven web diamond-operator multi-catch


    【解决方案1】:

    您也可以通过将其包含在 pom.xml 中来以这种方式添加它

     <properties>
       <maven.compiler.source>1.7</maven.compiler.source>
       <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    

    【讨论】:

      【解决方案2】:

      尝试在你的 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>
      

      【讨论】:

      • 是的,这行得通,但现在我有很多其他错误需要解决;(
      猜你喜欢
      • 2018-01-18
      • 2014-05-21
      • 2018-05-15
      • 2021-03-07
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      相关资源
      最近更新 更多