h3



  这些任务可以通过Ant构建完成,Hibernate提供了Ant Tasks及其构建脚本.由于Hibernate从2到3进行了重大重构,且包重新做了组织,因此Ant构建脚本也发生了巨大变化.在2中脚本样式为:

  <?xml version="1.0"?>

  <project name="anto builder"

  default="db" basedir=".">

  <!-- Set up properties containing important project directories -->

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

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

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

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

  <!-- Set up the class path for compilation and execution -->

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

  <!-- Include our own classes, of course -->

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

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

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

  <include name="*.jar"/>

  </fileset>

  </path>

  <target name="db" description="Runs HSQLDB database management UIagainst the database file--use when application is not running">

  <java classname="org.hsqldb.util.DatabaseManager"

  fork="yes">

  <classpath refid="project.class.path"/>

  <arg value="-driver"/>

  <arg value="org.hsqldb.jdbcDriver"/>

  <arg value="-url"/>

  <arg value="jdbc:hsqldb:${data.dir}/music"/>

  <arg value="-user"/>

  <arg value="sa"/>

  </java>

  </target>

  <!-- Teach Ant how to use Hibernate's code generation tool -->

  <taskdef name="hbm2java"

  classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"

  classpathref="project.class.path"/>

  <!-- Generate the java code for all mapping files in our source tree -->

  <target name="codegen"

  description="Generate Java source from the O/R mapping files">

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

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

  <include name="**/*.hbm.xml"/>

  </fileset>

  </hbm2java>

  </target>

  <!-- Create our runtime subdirectories and copy resources into them -->

  <target name="prepare" description="Sets up build structures">

  <mkdir dir="${class.root}"/>

  <!-- Copy our property files and O/R mappings for use at runtime -->

  <copy todir="${class.root}" >

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

  <include name="**/*.properties"/>

  <include name="**/*.hbm.xml"/>

  </fileset>

  </copy>

  </target>

  <!-- Compile the java source of the project -->

  <target name="compile" depends="prepare"

  description="Compiles all Java classes">

  <javac srcdir="${source.root}"

  destdir="${class.root}"

  debug="on"

  optimize="off"

  deprecation="on">

  <classpath refid="project.class.path"/>

  </javac>

  </target>

  <!-- Generate the schemas for all mapping files in our class tree -->

  <target name="schema" depends="compile"

  description="Generate DB schema from the O/R mapping files">

  <!-- Teach Ant how to use Hibernate's schema generation tool -->

  <taskdef name="schemaexport"

  classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"

  classpathref="project.class.path"/>

  <schemaexport properties="${class.root}/hibernate.properties"

  quiet="no" text="no" drop="no">

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

  <include name="**/*.hbm.xml"/>

  </fileset>

  </schemaexport>

  </target>

  </project>

  在3中,构建脚本为:

  <?xml version="1.0" encoding="GBK"?>

  <project name="Hibernate" default="anthbm2java" basedir=".">

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

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

  <property name="lib.dir" value="D:/eclipse/plugins/org.hibernate.eclipse_3.0.0.alpha4/lib" />

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

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

  <include name="*.jar"/>

  </fileset>

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

  </path>

  <path id="tasks.classpath">

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

  <include name="*.jar"/>

  </fileset>

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

  </path>

  <target name="anthbm2java">

  <taskdef name="hibernatetool"

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

  classpathref="tasks.classpath"/>

  <hibernatetool destdir="${class.dir}">

  <configuration configurationfile="hibernate.cfg.xml" >

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

  <include name="**/*.hbm.xml" />

  </fileset>

  </configuration>

  <hbm2ddl export="false" console="false" create="true" update="false" drop="false" outputfilename="broad.sql" delimeter=";"/>

  其中的delimeter属性在Hibernate-Tool 3 A5版本中不支持.

  <hbm2java generics="true" ejb3="false"/>

  <cfg2hbm/>

  <hbm2doc/>

  <!--

  <cfg2cfgXml/>

  这个任务在Hibernate-Tool 3 A5版本中不支持.

  -->

  </hibernatetool>

  </target>

  </project> Hibernate3构建脚本的变化

  这个脚本在Eclipse中检验过. 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值