Java Reference
In-Depth Information
of a project outside the IDE. This can be useful in maintaining automated builds for regression
testing—and of course, not all Java IDEs offer integrated support for Hibernate anyway, while
most of them do offer support for the Ant build tool. And besides, you might not be using an
IDE in the first place!
The Ant tasks are part of the Hibernate Tools download, which is largely oriented
toward use as an Eclipse plug-in. The Ant tools themselves rely upon a set of three JAR files:
hibernate-tools.jar , freemarker.jar , and jtidy-r8-21122004.jar . The hibernate-
tools.jar file is currently only available as a download with the rest of the plug-in files.
You will find the JAR file within the ZIP file in a directory called plugins\org.hibernate.
eclipse_X.x.x.x\lib\tools , where the X s are substituted for the Hibernate Tools version
number. The freemarker and jtidy JAR files will also be available from this directory. Since
these JAR files have no dependencies upon the other parts of the plug-in, you can copy
them to a directory with a less unwieldy name without further consequences.
How the Ant Tasks Work
Despite their diverse set of outputs, the Hibernate tasks actually all work in the same way. The
task is imported into Ant using the standard TaskDef element. This makes the Hibernate tools
libraries available to Ant itself, and allows you to select an appropriate element representing
the Hibernate tools to use in your script.
<taskdef
name="htools"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="classpath.tools"/>
The Hibernate Tools JAR file must be made available to Ant on the classpath—our exam-
ple uses a preexisting classpath declaration (referenced through its id of classpath.tools
see the “Configuring the Classpath” subsection later in this section).
A standard Ant target is declared to contain the set of operations that you want to perform.
<target name="exportDDL" depends="compile">
</target>
Within the target with any other standard (or imported) Ant tasks, you can then include
the element that you declared using the <taskdef> element. The other Hibernate task ele-
ments are only applicable within this task element.
<target name="exportDDL" depends="compile">
<htools destdir="${sql}">
</htools>
</target>
This outermost task element accepts three attributes, as listed in Table B-1.
Search WWH ::




Custom Search