将@Generated注释添加到JAXB生成的类

时间:2017-04-27 13:09:06

标签: java maven jaxb annotations

我正在尝试为JAXB从XSD生成的所有类添加@javax.annotation.Generated注释。

我正在使用 maven-jaxb2-plugin binding.xjb 文件来生成源代码。我看到JAXB插件 jaxb2-basics-annotate 应该可以解决问题。但我能找到的只是为特定类添加注释的示例。像这样:

<jaxb:bindings schemaLocation="csw/2.0.2/CSW-discovery.xsd" node="/xs:schema">
  <jaxb:bindings node="xs:complexType[@name='GetRecordsType']">
    <annox:annotate>
      <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetRecordsType" />
    </annox:annotate>
</jaxb:bindings>

如何为每个生成的文件执行此操作?这有可能吗?

1 个答案:

答案 0 :(得分:1)

您似乎正在使用highsource/jaxb2-annotate-plugin如果您还在使用他的highsource/maven-jaxb2-plugin,则内置支持此功能。只需将其添加到插件配置中:

<configuration>                                 
    <markGenerated>true</markGenerated>
</configuration>

同时检查controlling the output

如果您是官方的jaxb2插件,该功能也是内置的

<configuration>
    <addGeneratedAnnotation>true</addGeneratedAnnotation>
</configuration>