通过ant来部署和运行hibernate程序的配置文件,主要关注的是生成数据库的ddl
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="compile" basedir=".">
<property name="project.name" value="HelloWorld"/>
<property name="project.version" value="1.0" />
<property name="src.java.dir" value="src"/>
<property name="lib.dir" value="lib"/>
<property name="build.dir" value="bin"/>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</path>
<patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties" />
</patternset>
<!--org.hibernate.tool.ant.HibernateToolTask来自于hibernate-tools.jar和freemarker-2.3.19.jar-->
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.classpath"/>
<!--
export="true"表示所有的DDL语句并在数据库中执行
-->
<target name="schemaexport" depends="compile,copymetafiles" description="导出数据库的DDL,如果export=true表示所有的DDL语句并在数据库中执行">
<hibernatetool destdir="${basedir}">
<classpath path="${build.dir}" />
<configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
<hbm2ddl
drop="true"
create="true"
export="true"
outputfilename="helloworld-ddl.sql"
delimiter=";"
format="true"
/>
</hibernatetool>
</target>
<target name="clean" description="清除没用的文件夹">
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean" description="编译代码">
<javac srcdir="${src.java.dir}" destdir="${build.dir}" nowarn="on">
<classpath refid="project.classpath" />
</javac>
</target>
<target name="copymetafiles" description="拷贝系统属性配置文件">
<copy todir="${build.dir}">
<fileset dir="${src.java.dir}">
<patternset refid="meta.files" />
</fileset>
</copy>
</target>
<target name="hsqldbmanager" description="管理hsqldb数据库,使用此任务前,必须要启动hsqldb数据库">
<java
classname="org.hsqldb.util.DatabaseManagerSwing" fork="yes" classpathref="project.classpath" failonerror="true">
<arg value="-url"/>
<arg value="jdbc:hsqldb:hsql://localhost"/>
<arg value="-driver"/>
<arg value="org.hsqldb.jdbcDriver"/>
<arg value="-user"/>
<arg value="sa" />
</java>
</target>
<target name="run" depends="compile,copymetafiles" description="Build and run HelloWorld">
<java fork="true"
classname="hello.HelloWorld"
classpathref="project.classpath">
<classpath path="${build.dir}" />
</java>
</target>
</project>

被折叠的 条评论
为什么被折叠?



