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

问题描述 投票:1回答:1

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

我正在使用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>

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

java maven jaxb annotations
1个回答
1
投票

看来你正在使用highsource/jaxb2-annotate-plugin如果你也在使用他的highsource/maven-jaxb2-plugin,那么内置支持这个功能。只需将其添加到插件配置中:

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

还要检查controlling the output

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

<configuration>
    <addGeneratedAnnotation>true</addGeneratedAnnotation>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.