使用maven 构建hibernate应用

开发hibernate项目,可以采用手动下载hibernate jar包的方式,但由于hibernate项目的jar包较多,进行手工下载是非常繁琐的事情,可以采用maven进行hibernate包构建,可以大大的简化开发。而使用maven-hibernate 插件可以自动生成java 类和hbm配置文件。

1、首先修改项目的maven配置文件,增加hibernate 依赖项目,修改内容如下:

<dependency>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate-core</artifactId>
       <version>3.3.2.GA</version>
</dependency>

<dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-nop</artifactId>
         <version>1.5.2</version>
</dependency>

    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>5.0.8</version>
    </dependency>   



2、由于使用maven-hibernate项目中的hbm2java自动生成数据库对象,以及使用hbm2hbmxml生成hbm配置文件,还需要修改项目 pom.xml文件增加相应的插件配置

   <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
   <components>

     <component>
          <name>hbm2java</name>
          <!--<outputDirectory>target/hibernate3/generated-sources</outputDirectory>-->
          <outputDirectory>src/main/java</outputDirectory>
      </component>
      <component>
          <name>hbm2hbmxml</name>
          <outputDirectory>src/main/resources/</outputDirectory>
      </component>
      <component>
      <name>hbm2cfgxml</name>
      <!--<outputDirectory>target/hibernate3/generated-mappings</outputDirectory>-->
      <outputDirectory>src/main/resources/</outputDirectory>
      </component>      
     <componentProperties>
        <drop>true</drop>
        <jdk5>true</jdk5>
        <packagename>>xerlly.java.maven.HibernetTest.Model</packagename>
        <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
        <!-- <propertyfile>src/main/resources/jdbc.properties</propertyfile> -->
        <!--  <revengfile>src/main/resources/hibernate.reveng.xml</revengfile>-->
     </componentProperties>
   </components>

  </configuration>

<dependencies>

    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>5.0.8</version>
    </dependency>   
</dependencies>
   </plugin>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值