Hibernate version:2.1
I am able to use hibernate with my Simple user class. I had generated the xml file manually. I have made an attempt to use XDoclet and written a ant script to build my files and generate User.hbm.xml file for me using "hibernatedoclet".. My ant script looks like this :
Code:
<project name="Catapult" default="compile" basedir=".">
<property file="build.properties"/>
<property file="${user.home}/build.properties"/>
<property name="build.home" value="${basedir}/web"/>
<property name="dist.home" value="${basedir}/dist"/>
<property name="docs.home" value="${basedir}/docs"/>
<property name="src.home" value="${basedir}/src"/>
<property name="web.home" value="${basedir}/web"/>
<path id="compile.classpath">
<!-- Include all JAR files that will be included in /WEB-INF/lib -->
<!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->
<!--
<pathelement location="${foo.jar}"/>
-->
<!-- Include all elements that Tomcat exposes to applications -->
<pathelement location="${catalina.home}/common/classes"/>
<!--<fileset dir="${catalina.home}/common/endorsed">
<include name="*.jar" />
</fileset>-->
<fileset dir="${catalina.home}/common/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${web.home}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!--<pathelement location="${catalina.home}/shared/classes" />
<fileset dir="${catalina.home}/shared/lib">
<include name="*.jar" />
</fileset>-->
</path>
<!-- ==================== All Target ====================================== -->
<!--
The "all" target is a shortcut for running the "clean" target followed
by the "compile" target, to force a complete recompile.
-->
<target name="all" depends="clean,compile" description="Clean build and dist directories, then compile"/>
<!-- ==================== Clean Target ==================================== -->
<!--
The "clean" target deletes any previous "build" and "dist" directory,
so that you can be ensured the application can be built from scratch.
-->
<target name="clean" description="Delete old build and dist directories">
<delete dir="${build.home}/web/WEB-INF/classes"/>
<delete dir="${dist.home}"/>
</target>
<!-- ==================== Compile Target ================================== -->
<!--
The "compile" target transforms source files (from your "src" directory)
into object files in the appropriate location in the build directory.
This example assumes that you will be including your classes in an
unpacked directory hierarchy under "/WEB-INF/classes".
-->
<target name="compile" depends="clean" description="Compile Java sources">
<!-- Compile Java classes as necessary -->
<mkdir dir="${build.home}/WEB-INF/classes"/>
<javac srcdir="${src.home}" destdir="${build.home}/WEB-INF/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
<classpath refid="compile.classpath"/>
</javac>
<!-- Copy application resources -->
<copy todir="${build.home}/WEB-INF/classes">
<fileset dir="${src.home}" excludes="**/*.java"/>
</copy>
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/ApplicationResources-nav.properties"
tofile="${build.home}/WEB-INF/classes/ApplicationResources-nav.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/ApplicationResources-rms.properties"
tofile="${build.home}/WEB-INF/classes/ApplicationResources-rms.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/ApplicationResources-user.properties"
tofile="${build.home}/WEB-INF/classes/ApplicationResources-user.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/ApplicationResources.properties"
tofile="${build.home}/WEB-INF/classes/ApplicationResources.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/commons-logging.properties"
tofile="${build.home}/WEB-INF/classes/commons-logging.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/defaultProperties.properties"
tofile="${build.home}/WEB-INF/classes/defaultProperties.properties" />
<!-- Copy default application resources file -->
<copy overwrite="true" file="${basedir}/src/log4j.properties"
tofile="${build.home}/WEB-INF/classes/log4j.properties" />
</target>
<target name="generate-hbm"
description="Generates Hibernate class"
depends="compile">
<!-- Define the hibernate doclet task -->
<taskdef name="hibernatedoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask"
classpathref="project.class.path">
</taskdef>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet
destdir="${src.home}"
excludedtags="@version,@author,@todo"
force="true"
verbose="true">
<fileset dir="${src.home}">
<include name="**/*.java"/>
</fileset>
</hibernatedoclet>
</target>
</project>
There is a build.properties file where the variables are defined
Code:
# Application name
app.name=Catapult
# Application version
app.version=0.1-dev
# Context path to install this application on
app.path=/Catapult
#user home
user.home=/catapult/server
# Tomcat 4 installation directory
catalina.home=/Tomcat
# Manager webapp url, username and password
manager.url=http://localhost:8080/catapult
The script works fine for building class files. Somehow its not creating hibernate mapping xml file for me... Anyone who has used this feature, can u please guide me.
Thanks in Advance...
Cheers !!\
Gunjan