2012-05-10 111 views
14

我遵循JPA modelgen guide,我能够生成我需要的规范元模型。有了这个POM设置:JPA Hibernate通过maven生成元模型

<plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArgument>-proc:none</compilerArgument> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.bsc.maven</groupId> 
       <artifactId>maven-processor-plugin</artifactId> 
       <version>2.0.6-redhat</version> 
       <executions> 
        <execution> 
         <id>process</id> 
         <goals> 
          <goal>process</goal> 
         </goals> 
         <phase>generate-sources</phase> 
         <configuration> 
          <outputDirectory>target/metamodel</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>1.3</version> 
       <executions> 
        <execution> 
         <id>add-source</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>add-source</goal> 
         </goals> 
         <configuration> 
          <sources> 
           <source>target/metamodel</source> 
          </sources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

生成的源在指定目录中正确地创建和我必须手动将它指定Eclipse项目类路径中的源来使用它。当我触发一个maven日志显示cannot find symbolduplicate class,我仍然获得成功构建。所以我的问题是,创建元模型的这种预期/正确的行为?还是我错过了cofig的东西?由于

+0

FIY,看看[jpa-metamodel-with-maven](https://jinahya.wordpress.com/2014/03/29/jpa-metamodel-with-maven/) –

回答

14

我还使用JPA模型生成,我没有你的描述,也许我的配置能有所帮助,我看到一些差异的问题,第一个是maven-processor-plugin

<plugin> 
    <groupId>org.bsc.maven</groupId> 
    <artifactId>maven-processor-plugin</artifactId> 
    <version>2.1.0</version> 
    <executions> 
    <execution> 
     <id>process</id> 
     <goals> 
     <goal>process</goal> 
     </goals> 
     <phase>generate-sources</phase> 
     <configuration> 
     <processors> 
      <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> 
     </processors> 
     </configuration> 
    </execution> 
    </executions> 
    <dependencies> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-jpamodelgen</artifactId> 
     <!--version>1.2.0.Final</version--> 
     <version>4.3.4.Final</version> 
    </dependency> 
    </dependencies> 
</plugin> 

正如你可以看到我不得不添加hibernate-jpamodelgen作为依赖和处理器属性。

我不确定是否需要build-helper-maven-plugin将生成的源目录添加到源路径。我没有使用它,它适用于我,但也许这是因为我使用默认输出路径生成的源。

相关问题