【问题标题】:JAXB Java EE generate entity class from SchemaJAXB Java EE 从 Schema 生成实体类
【发布时间】:2013-02-26 20:20:46
【问题描述】:

我正在使用用于 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 插件在生成类时使用包含的这些注释来注释类文件?

【问题讨论】:

    标签: java jakarta-ee


    【解决方案1】:

    JAXB 使用的 XJC 编译器有一个插件 api,允许自定义生成的 java 代码。好像有plugin to add arbitrary annotations,也许这已经解决了你的问题。

    有关可能性的更复杂示例,您可以查看source codefluent api plugin

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多