【问题标题】:Maven not compiling anotationsMaven不编译注释
【发布时间】:2013-12-03 11:16:24
【问题描述】:

我有一个带有注释的类:

@WebService(endpointInterface = "ws.AccOpsProcessorWS") 

每当我运行 mvn clean install 时,都会出现以下错误:

annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@WebService(endpointInterface = "ws.AccOpsProcessorWS")

我无法理解这里的问题。 eclipse和机器中的JDK版本是1.6

【问题讨论】:

  • 您的 maven pom.xml 在编译器插件中不正确。这条线是不言而喻的annotations are not supported in -source 1.3 它说你已经配置了 1.3

标签: java maven-2


【解决方案1】:

错误消息很清楚use -source 5 or higher to enable annotations。之后版本51.6 :) 你的pom.xml 配置错误。

Maven对JDK版本的配置与eclipse不同,请检查是否正确。

Configure JDK version in maven-compiler-plugin

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

Annotations in Java 可从 JDK 1.5 获得

【讨论】:

  • 如果我删除注释一切正常。注释有什么问题?
  • 注解是在 Java 1.5 中引入的
  • 我知道。我的编译器是 1.6
  • 好的,发布您的pom.xmlmaven-compiler-plugin 部分。我的信息很清楚:use -source 5 or higher to enable annotations。您是在 Eclipse 或 maven 中使用这个新的 API 吗?
  • 使用mvn help:effective-pom 向您展示您的有效pom(包括所有父pom 和主pom)是什么。请注意,主 pom 取决于您安装的 Maven 版本,我记得主 POM 中的 maven-compiler-plugin 配置为目标 1.4 的版本。
【解决方案2】:

您是否在定义要在哪个 JDK 下编译?例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 2013-06-29
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 2014-08-01
    相关资源
    最近更新 更多