|
| 1 | +<!-- |
| 2 | + ~ Copyright 2004 - 2025 Red Hat, Inc. |
| 3 | + ~ |
| 4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + ~ you may not use this file except in compliance with the License. |
| 6 | + ~ You may obtain a copy of the License at |
| 7 | + ~ |
| 8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + ~ |
| 10 | + ~ Unless required by applicable law or agreed to in writing, software |
| 11 | + ~ distributed under the License is distributed on an "AS IS" basis, |
| 12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + ~ See the License for the specific language governing permissions and |
| 14 | + ~ limitations under the License. |
| 15 | + --> |
| 16 | + |
| 17 | +[](https://tools.hibernate.org) |
| 18 | + |
| 19 | +# Hibernate Tools Ant : Reference Guide |
| 20 | + |
| 21 | +## 1. The `<hibernatetool>` Task |
| 22 | + |
| 23 | +### 1.1 `<hibernatetool>` task definition |
| 24 | +To use the Ant tasks you need to have the `<hibernatetool>` task defined. |
| 25 | +That is done in your `build.xml` file by inserting the following XML. |
| 26 | + |
| 27 | +```xml |
| 28 | +<ivy:cachepath organisation="org.hibernate.tool" module="hibernate-tools-ant" revision="${hibernate-tools.version}" |
| 29 | + pathid="hibernate-tools.path" inline="true"/> |
| 30 | +<ivy:cachepath organisation="${jdbc-driver.org}" module="${jdbc-driver.module}" revision="${jdbc-driver.version}" |
| 31 | + pathid="jdbc-driver.path" inline="true"/> |
| 32 | + |
| 33 | +<path id="classpath"> |
| 34 | + <path refid="hibernate-tools.path"/> |
| 35 | + <path refid="jdbc-driver.path"/> |
| 36 | +</path> |
| 37 | + |
| 38 | + |
| 39 | +<taskdef name="hibernatetool" |
| 40 | + classname="org.hibernate.tool.ant.HibernateToolTask" |
| 41 | + classpathref="classpath" /> |
| 42 | +``` |
| 43 | +The `<taskdef>`in the snippet above defines an Ant task called `hibernatetool` |
| 44 | +which now can be used anywhere in your `build.xml` file. |
| 45 | + |
| 46 | +The snippet above also uses [Apache Ivy](https://ant.apache.org/ivy/) to handle the library dependencies. |
| 47 | +Of course you could also explicitly handle these dependencies yourself in the `build.xml` |
| 48 | +file. In addition, you will need to define properties (or replace the variables) for |
| 49 | +the jdbc driver and for the version information. See an example in the snippet below: |
| 50 | + |
| 51 | +```xml |
| 52 | +<property name="hibernate-tools.version" value="7.0.0.Final"/> |
| 53 | +<property name="jdbc-driver.org" value="com.h2database"/> |
| 54 | +<property name="jdbc-driver.module" value="h2"/> |
| 55 | +<property name="jdbc-driver.version" value="2.3.232"/> |
| 56 | +``` |
| 57 | + |
| 58 | + |
0 commit comments