更新时间:2022-11-28 12:33:24
我假设您正在询问如何让JAXB编译器自动注释生成的类.有一个用于添加注释的JAXB插件: http://confluence.highsource.org/display/J2B /Annotate + Plugin
I assume that you're asking how to have the JAXB compiler automatically annotate the generated classes. There's a JAXB plugin for adding annotations: http://confluence.highsource.org/display/J2B/Annotate+Plugin
您可以像这样将其挂接到Maven构建的generate-sources
阶段:
You can hook it into the generate-sources
phase of a Maven build like so:
<build>
<!-- snip -->
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>path/to/your/schema.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>path/to/your/custom-bindings.xjb</include> <!-- if you choose to use a custom bindings file instead of inline annotations in the xsd -->
</bindingIncludes>
<forceRegenerate>true</forceRegenerate>
<extension>true</extension>
<episode>false</episode>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
如果上面的插件不能完全满足您的要求(我认为应该如此,它看起来很灵活),那么进行自己的修改就不会太困难(我在添加副本构造函数之前已经做了此事)到生成的类).
If the above plugin doesn't do exactly what you want (which I think it should, it looks pretty flexible), it shouldn't be too difficult to roll your own modification (I have done this before for adding copy constructors to generated classes).