The whole idea of the Hibernate XDoclet task is that metadata included in the Java source is used to create the mapping files and the jboss-service.xml. You can then jar these up into a SAR with the class files, and away you go.
Code:
<!-- =================================================================== -->
<!-- generates the hibernate HBM.XML files and SAR descriptor -->
<!-- =================================================================== -->
<target name="generate-Hibernate"
description="Generates Hibernate class descriptor files."
depends="compile">
<!-- copy additional resources for the Hibernate XDoclet task to the
mergedir -->
<fileset dir="${src.dir}">
<include name="**/hibernate/hibernate-properties-*.xml"/>
</fileset>
</copy>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet
destdir="${build.resources}/sar/hibernate"
excludedtags="@version,@author,@todo,@see,@desc"
addedtags="@xdoclet-generated at ${TODAY}@copyright Galenworks,@author Galenworks,@version ${version}"
force="${xdoclet.force}"
mergedir="${build.resources}/sar/hibernate"
verbose="false">
<fileset dir="${src.dir}">
<include name="**/hibernate/*.java"/>
</fileset>
<hibernate version="2.0"/>
<jbossservice
destdir="${build.resources}/sar/hibernate"
serviceName="Hibernate"
jndiName="${hibernate.jndi.name}"
dataSource="${hibernate.datasource.name}"
dialect="${hibernate.dialect}"
useOuterJoin="true"
transactionManagerStrategy="net.sf.hibernate.transaction.JBossTransactionManagerLookup"
transactionStrategy="net.sf.hibernate.transaction.JTATransactionFactory"
userTransactionName="UserTransaction"
/>
</hibernatedoclet>
</target>
The jbossservice tag in there creates the jboss-service.xml with all the generated hbm.xml file names in the MapResources, relative to the destdir of the main hibernatedoclet tag.
Now create the SAR:
Code:
<target depends="generate-Hibernate" name="hibernate-sar">
<jar destfile="${build.lib}/galenworksHibernateStartup.sar">
<!-- Get the generated hbm.xml files -->
<fileset dir="${build.resources}/sar/hibernate">
<include name="**/*.hbm.xml"/>
</fileset>
<metainf dir="${build.resources}/sar/hibernate">
<include name="jboss-service.xml"/>
</metainf>
</jar>
<antcall target="hibernate-schemaexport" />
</target>
The hibernate-schemaexport target is:
Code:
<!-- =================================================================== -->
<!-- Generate the database creation scripts from the Hibernate schema. -->
<!-- =================================================================== -->
<target name="hibernate-schemaexport">
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<fileset dir="${lib.dir}">
<include name="hibernate2.1b6.jar"/>
<include name="cglib-asm.jar"/>
<include name="commons-collections.jar"/>
<include name="commons-beanutils.jar"/>
<include name="commons-lang.jar"/>
<include name="commons-logging.jar"/>
<include name="dom4j.jar"/>
<include name="jaas.jar"/>
<include name="jcs.jar"/>
<include name="jdbc2_0-stdext.jar"/>
<include name="dom4j.jar"/>
<include name="jaas.jar"/>
<include name="jcs.jar"/>
<include name="jdbc2_0-stdext.jar"/>
<include name="odmg.jar"/>
</fileset>
<fileset dir="${build.lib}">
<include name="galenworksHibernateStartup.sar" />
<include name="galenworksCommon.jar" />
</fileset>
</classpath>
</taskdef>
<schemaexport output="${basedir}/${build.resources}/drop-and-build.sql"
properties="${hibernate.connection.config}"
quiet="yes"
delimiter=";"
text="yes">
<fileset dir="${build.resources}/sar/hibernate">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
<schemaexport output="${basedir}/${build.resources}/drop.sql"
properties="${hibernate.connection.config}"
quiet="yes"
drop="yes"
delimiter=";"
text="yes">
<fileset dir="${build.resources}/sar/hibernate">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
This gives the base database creation scripts. We have some additional scripts that build indexes, stored procedures etc, that we build by hand.
So, if you can generate the Java source with Hibernate XDoclet tags, you
could have XDoclet do the rest for you.
Cheers,
Sherman