我正在使用 JAXB 的 Maven 插件从 XML 模式文档生成类。 我的 POM 包含以下内容
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<clearOutputDir>false</clearOutputDir>
<outputDirectory>src/main/java</outputDirectory>
<schemaDirectory>src/main/webapp/schemas</schemaDirectory>
<includeSchema>**/*.xsd</includeSchema>
<bindingDirectory>src/main/resources/bindings</bindingDirectory>
<enableIntrospection>false</enableIntrospection>
</configuration>
</plugin>
我使用的是JPA 2的Eclipselink规范,当JAXB根据schema生成类时,不包含下面的注解。
@Entity
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
目前我只是在每次使用 Maven 进行干净编译时手动添加这些。我想知道是否有办法让 JAXB 插件在生成类时使用包含的这些注释来注释类文件?
最佳答案
JAXB 使用的 XJC 编译器有一个插件 api,允许自定义生成的 java 代码。似乎有一个plugin to add arbitrary annotations ,也许这已经解决了您的问题。
有关可能性的更复杂示例,您可以查看 source code的 fluent api plugin .
关于java - JAXB Java EE 从 Schema 生成实体类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342282/