在实现持久层中工具的应用(4)

 

通过ANT使用HIBERNATETOOLS

基于HIBERNATE3环境中,如果想通过ANT来完成HBM文件到DDLPOJO的转换,首先,需要以下库文件:

hibernate-tools.jar

hibernate3.jar

freemarker.jar

mysql-connector-java-5.0.7-bin.jar

antlr-2.7.6.jar

cglib-nodep-2.1_3.jar

commons-collections.jar

commons-logging.jar

dom4j-1.6.1.jar

接下来,需要准备hibernate.properties文件,内容如下:

hibernate.dialect=org.hibernate.dialect.MySQLDialect

hibernate.connection.driver_class=com.mysql.jdbc.Driver

hibernate.connection.url=jdbc:mysql://localhost/test

hibernate.connection.username=root

hibernate.connection.password=root

 

ANTBUILD文件内容如下:

<project name="testHibernate" default="schemaexport" basedir=".">

    <property name="source.root" value="src"/>

    <property name="config.dir" value="config"/>

    <property name="class.root" value="bin"/>

    <property name="lib.dir" value="lib"/>

 

    <path id="project.class.path">        

    <pathelement path="${classpath}"/>

        <pathelement location="${class.root}"/>

    <!-- Include jars in the project library directory -->

        <fileset dir="${lib.dir}">

          <include name="*.jar"/>

        </fileset>       

    </path>

    <target name="schemaexport">

        <taskdef name="schemaexport"

            classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"

        classpathref="project.class.path"/>       

        <schemaexport

            properties="${config.dir}/hibernate.properties"

            quiet="no" text="no" drop="no" delimiter=";" output="${config.dir}/schema-export.sql">

            <fileset dir="${source.root}">

              <include name="mytest/hibernate/firstSample/User.hbm.xml"/>

            </fileset>

        </schemaexport>

    </target>

    <target name="schemaupdate">

        <taskdef name="schemaupdate"

            classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"

            classpathref="project.class.path"/>    

        <schemaupdate

            properties="${config.dir}/hibernate.properties"

            quiet="no">

            <fileset dir="src">

            <include name="mytest/hibernate/firstSample/User.hbm.xml"/>

            </fileset>

        </schemaupdate>

    </target>

    <target name="hbm2java">

       <taskdef name="hbm2java"

           classname="org.hibernate.tool.ant.HibernateToolTask"

           classpathref="project.class.path"/>

       <hbm2java destdir="${source.root}">

           <configuration configurationfile="${config.dir}/hibernate.cfg.xml" /> 

           <hbm2java ejb3="false"/>

       </hbm2java> 

    </target>

</project>

 

ECLIPSEPROJECT的文件结构如下:

 str1

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值