包含hbm.xml、XDoclet和Annotation方式的hibernate.cfg.xml
用hibernate一段时间,期间写过hbm.xml,也通过XDoclet产生过Java,
最后采用的是annotation方式。保留一份包含了hbm.xml方式和XDoclet
方式的hibernate.cfg.xml文件,以备查询。
<?xml version="1.0"?>
<project name="RcpaMSMSDisplay" default="compile" basedir=".">
<property name="src.dir" value="${basedir}/src" />
<property name="test.dir" value="${basedir}/test" />
<property name="classes.dir" value="${basedir}/WEB-INF/classes" />
<property name="report.dir" value="${basedir}/report" />
<property name="tomcat.dir" value="C:/ApacheGroup/Tomcat5.5" />
<property name="lib.dir" value="${basedir}/WEB-INF/lib" />
<path id="build.classpath">
<fileset file="${lib.dir}/*.jar" />
<fileset file="${tomcat.dir}/common/lib/*-api.jar" />
<pathelement path="${classes.dir}" />
</path>
<target name="clean">
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
</target>
<target name="compile" depends="copy-resources">
<javac destdir="${classes.dir}" srcdir="${src.dir}:${test.dir}">
<classpath refid="build.classpath" />
</javac>
</target>
<target name="copy-resources">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java" />
<exclude name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="copy-hbm-xml">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="generate" description="Generates Hibernate class descriptor files." depends="compile">
<!-- Define the hibernatedoclet task -->
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
<classpath>
<fileset dir="${lib.dir}/xdoclet">
<include name="*.jar" />
</fileset>
</classpath>
</taskdef>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet destdir="${src.dir}" excludedtags="@version,@author,@todo" verbose="false">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<hibernate version="3.0" />
</hibernatedoclet>
</target>
<target name="initdb" depends="compile">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />
<hibernatetool destdir="${classes.dir}">
<classpath>
<path location="${classes.dir}" />
</classpath>
<annotationconfiguration configurationfile="src/hibernate.cfg.xml" />
<hbm2ddl create="true" />
</hibernatetool>
</target>
<target name="run" depends="compile">
<java fork="true" classname="cn.ac.rcpa.msms.tools.ProjectManager" classpathref="build.classpath">
<classpath path="${classes.dir}" />
<arg value="${action}" />
<arg value="${project}" />
<arg value="${description}" />
</java>
</target>
<target name="test" depends="compile" description="run junit test">
<delete dir="${report.dir}" />
<mkdir dir="${report.dir}" />
<junit dir="." fork="true" printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath refid="build.classpath" />
<formatter type="brief" />
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/*Test.*" />
<include name="**/Test*.*" />
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
</fail>
</target>
</project>
最后采用的是annotation方式。保留一份包含了hbm.xml方式和XDoclet
方式的hibernate.cfg.xml文件,以备查询。
<?xml version="1.0"?>
<project name="RcpaMSMSDisplay" default="compile" basedir=".">
<property name="src.dir" value="${basedir}/src" />
<property name="test.dir" value="${basedir}/test" />
<property name="classes.dir" value="${basedir}/WEB-INF/classes" />
<property name="report.dir" value="${basedir}/report" />
<property name="tomcat.dir" value="C:/ApacheGroup/Tomcat5.5" />
<property name="lib.dir" value="${basedir}/WEB-INF/lib" />
<path id="build.classpath">
<fileset file="${lib.dir}/*.jar" />
<fileset file="${tomcat.dir}/common/lib/*-api.jar" />
<pathelement path="${classes.dir}" />
</path>
<target name="clean">
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
</target>
<target name="compile" depends="copy-resources">
<javac destdir="${classes.dir}" srcdir="${src.dir}:${test.dir}">
<classpath refid="build.classpath" />
</javac>
</target>
<target name="copy-resources">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java" />
<exclude name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="copy-hbm-xml">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="generate" description="Generates Hibernate class descriptor files." depends="compile">
<!-- Define the hibernatedoclet task -->
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
<classpath>
<fileset dir="${lib.dir}/xdoclet">
<include name="*.jar" />
</fileset>
</classpath>
</taskdef>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet destdir="${src.dir}" excludedtags="@version,@author,@todo" verbose="false">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<hibernate version="3.0" />
</hibernatedoclet>
</target>
<target name="initdb" depends="compile">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />
<hibernatetool destdir="${classes.dir}">
<classpath>
<path location="${classes.dir}" />
</classpath>
<annotationconfiguration configurationfile="src/hibernate.cfg.xml" />
<hbm2ddl create="true" />
</hibernatetool>
</target>
<target name="run" depends="compile">
<java fork="true" classname="cn.ac.rcpa.msms.tools.ProjectManager" classpathref="build.classpath">
<classpath path="${classes.dir}" />
<arg value="${action}" />
<arg value="${project}" />
<arg value="${description}" />
</java>
</target>
<target name="test" depends="compile" description="run junit test">
<delete dir="${report.dir}" />
<mkdir dir="${report.dir}" />
<junit dir="." fork="true" printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath refid="build.classpath" />
<formatter type="brief" />
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/*Test.*" />
<include name="**/Test*.*" />
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
</fail>
</target>
</project>