I spent many hours discovering that I must have my schemaexport target depend on my "dist" target. Why is this?
(1) I thought schemaexport would have to have access to the hbm.xml files, but instead it has access to the compile class files originally in the bin directory. Does it not need access to the hbm.xml files I had hibernatedoclet create?
(2) Why does it need my pojos in a jar file in the path?
Below is my build.xml file that works for a trival class. I don't know why it works, however.
Thanks,
Siegfried
<?xml version="1.0" encoding="UTF-8"?>
<project name="Blog" default="generate-hibernate" basedir=".">
<property name="xdoclet.lib.dir" value="C:\Documents and Settings\Siegfried\My Documents\dev\XDoclet\xdoclet-1.2.3\lib" />
<property name="hibernate" location="C:/Documents and Settings/Siegfried/My Documents/dev/hibernate/hibernate-3.0" />
<property name="lib.dir" value="C:\Documents and Settings\Siegfried\My Documents\dev\hibernate\hibernate-3.0" />
<property name="hibernate.dir" value="src" />
<property name="src.dir" value="src" />
<property name="lib" location="lib" />
<property name="bin" location="bin" />
<property name="merge.dir" value="merge" />
<property name="jdbc" location="C:\Documents and Settings\Siegfried\My Documents\dev\jdbc-mssql-jtds\1.1\jtds-1.1.jar" />
<property name="name" value="casestudy"/>
<path id="classpath.base">
<pathelement location="${bin}" />
<pathelement location="${hibernate}/hibernate3.jar" />
<fileset dir="${hibernate}/lib" includes="**/*.jar" />
<pathelement location="${jdbc}" />
<pathelement location="C:/WinOOP/PureGamesInc/eclipse/PureGamesInc/lib/commons-lang-2.1/commons-lang-2.1.jar"/>
</path>
<path id="classpath.run">
<path refid="classpath.base" />
<pathelement location="${jdbc}"/>
<pathelement location="${lib}/${name}.jar"/>
</path>
<path id="xdoclet.lib.path">
<fileset dir="${xdoclet.lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="generate-hibernate">
<taskdef name="hibernatedoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask"
classpathref="xdoclet.lib.path" />
<!-- Generate Hibernate mapping files -->
<hibernatedoclet destdir="${hibernate.dir}"
mergeDir="${merge.dir}">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<hibernate version="2.0" />
</hibernatedoclet>
</target>
<target name="init">
<mkdir dir="${bin}" />
<mkdir dir="${lib}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${bin}">
<classpath refid="classpath.base" />
</javac>
<copy todir="${bin}">
<fileset dir="${src.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${bin}" />
<delete dir="${lib}" />
<delete>
<fileset dir="." includes="${name}db.*"/>
</delete>
<delete file="${name}.sql"/>
</target>
<target name="dist" depends="compile">
<jar destfile="${lib}/${name}.jar" basedir="${bin}" />
</target>
<target name="schemaexport" depends="dist">
<
java classname="org.hibernate.tool.hbm2ddl.SchemaExport" classpathref="classpath.run">
<arg line="--config=hibernate.cfg.xml --output=${name}.sql"/>
</java>
</target>
</project>