I'm having a strange problem with the schemaexport Ant taskdef, which I'd like to use. When I run it, my mapping file isn't found, and I end up with an empty schema. However, when I "manually" run the SchemaExport tool using what seems to be an equivalent java task in the same build.xml, I can get it to work by explicitly listing the filename.
Since this defeats the purpose of the "**/*.hbm.xml" wildcard, I'd really like to get the taskdef-based target working. Has anyone seen a problem like this, or can someone help me figure out what I'm doing wrong?
Here are the relevant excerpts from the build.xml. The target that works is "schema2", the one that doesn't is the preceding one, "schema" (both depend on a "compile" task I've omitted for brevity; that just compiles the Java classes to the classes directory, and works fine):
Code:
<project name="Hibernate Examples" default="schema" 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>
<!-- Teach Ant how to use Hibernate's schema generation tool -->
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>
<!-- Create our necessary subdirectories, and copy resources into them. -->
<target name="prepare" description="Sets up build structures">
<mkdir dir="${class.root}"/>
<!-- Copy in 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>
<!-- Generate the schemas for all mapping files in our source tree -->
<target name="schema" depends="compile"
description="Generate DDL for schema from the O/R mapping files">
<schemaexport properties="${class.root}/hibernate.properties"
quiet="no" text="yes" drop="no" delimiter=";"
output="${data.dir}/schema-export.ddl"/>
<fileset dir="${class.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</target>
<target name="schema2" depends="compile"
description="Generate DDL for schema from the O/R mapping files">
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport"
failonerror="true" fork="true">
<arg value="--text"/>
<arg value="--delimiter=;"/>
<arg value="--properties=${class.root}/hibernate.properties"/>
<arg value="--output=${data.dir}/my_schema.ddl"/>
<arg value="${class.root}/com/brunchboy/hh/Track.hbm.xml"/>
<classpath refid="project.class.path"/>
</java>
</target>
</project>