RSS

Creating java domain objects from a database with an Ant task and Hibernate tools

08 May

This is the third way we mentioned in this parent post of creating java domain objects, or data access objects, mapping files.
We need to create an Ant task within our build.xml file in order to generate our domain objects, daos or xml mapping files.
Once this is done, we have to execute ant hbm (our task name) and our files will be generated. Notice that you need to include a reference to every library we are going to use (hibernate-tools, freemarker, log libraries, …).

<?xml version="1.0" encoding="UTF-8"?>
<project name="HibernateExample">
	<!-- classpath -->
	<path id="toolslib">
		<path location="/hopcroft/.m2/repository/org/hibernate/hibernate-tools/3.2.0.ga/hibernate-tools-3.2.0.ga.jar" />
		<path location="/hopcroft/.m2/repository/org/hibernate/hibernate-core/3.3.1.GA/hibernate-core-3.3.1.GA.jar" />
		<path location="/hopcroft/.m2/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar" />
		<path location="/hopcroft/.m2/repository/org/slf4j/slf4j-log4j12/1.5.6/slf4j-log4j12-1.5.6.jar" />
		<path location="/hopcroft/.m2/repository/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar" />
		<path location="/hopcroft/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar" />
		<path location="/hopcroft/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar" />
		<path location="/hopcroft/.m2/repository/freemarker/freemarker/2.3.8/freemarker-2.3.8.jar" />
		<path location="/hopcroft/.m2/repository/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev.jar" />
	</path>


	<!-- our ant target -->
	<target name="hbm">
		<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
		<hibernatetool destdir="generated-ant">
			<!-- we use our hibernate.cfg.xml -->
			<jdbcconfiguration configurationfile="src/main/resources/hibernate.cfg.xml">
			</jdbcconfiguration>
			<classpath>
				<path location="classes-ant" />
			</classpath>
			<hbm2hbmxml/>
			<hbm2java jdk5="true" ejb3="true" />
			<hbm2dao>
		</hibernatetool>
	</target>
</project>
 
2 comentarios

Publicado por en 8 mayo, 2011 en Hibernate

 

Etiquetas: , , ,

2 Respuestas a “Creating java domain objects from a database with an Ant task and Hibernate tools

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

 
A %d blogueros les gusta esto: