2011-05-30 86 views
0

我想用maven生成我的类和hibernate.cfg.xml。 嗯,我有我的项目中的类取决于生成的Java文件,所以我可能要执行这个过程项目清理或如此?我不知道如何配置这个工作,所以这是一个问题。 那么我有一个database.properties文件是好的,我修改了很多hbm.xml文件。现在我想从hbm.xml文件和database.properties文件中生成hibernate.cfg.xml和所有java文件。 我目前的Maven项看起来是这样的:Maven与休眠工具

<plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>hibernate3-maven-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>hbm2java</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbm2java</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbm2java</name> 
           <implementation>configuration</implementation> 
           <outputDirectory>src/main/java</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <jdk5>true</jdk5> 
          <ejb3>true</ejb3> 
          <propertyfile>src/main/resources/database.properties</propertyfile> 
         </componentProperties> 
        </configuration> 
       </execution> 
      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>5.0.8</version> 
       </dependency> 
       <dependency> 
        <groupId>cglib</groupId> 
        <artifactId>cglib-nodep</artifactId> 
        <version>2.1_3</version> 
       </dependency> 
      </dependencies> 
     </plugin> 

谁能帮助我?我真的不知道该怎么做,才能让这件事情起作用。

+0

'generate-sources'似乎是一个apt'phase'来运行这个。如果有的话,你得到的错误是什么?另外,如果要在每次构建期间重新生成源代码,则不希望将生成的源代码放在“src/main/java”中。 – Raghuram 2011-05-30 08:57:38

+0

我通过编写我自己的maven插件解决了我的问题,该插件负责在配置文件中添加xml映射元素。如果有人对这个插件感兴趣,请给我一个下午左右的时间。 – 2011-05-30 13:34:43

回答

0

那么我的解决方案是使用我的自写插件。 在这里,你可以找到它:http://uploaded.to/file/j3j7b652

使用范例:

<plugin> 
     <groupId>com.blazebit</groupId> 
     <artifactId>HibernateCfgBuilder</artifactId> 
     <version>1.0</version> 
     <executions> 
      <execution> 
       <id>HibernateCfgBuilder</id> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>HibernateCfgBuilder</goal> 
       </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <hbmXmlFilesDir>src/main/resources/com/company/model/</hbmXmlFilesDir> 
      <configFile>target/classes/hibernate.cfg.xml</configFile> 
      <packageName>com.company.model</packageName> 
     </configuration> 
    </plugin> 

如果您有任何疑问,请咨询。配置属性全部记录在案。

+0

找不到页面。 =( – Marvo 2011-12-29 01:10:00

+0

我更新了链接,只是让我知道它是否再次爆发 – 2012-01-05 15:03:01

+0

它又破了。 – 2012-04-20 19:47:11