I'm trying to generate POJO's from mapping xml files. I read something about adding an ant task, to do it easily.
I've added this xml below to my project's build-impl.xml in Netbeans, but nothing happens:
<target name="codegen">
<echo>Zippzip</echo>
<taskdef name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="javac.classpath"/>
<hbm2java
output="generated/src/">
<fileset dir="cat/model/">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
I'm beginner to Netbeans, Ant and Hibernate, can anyone help me out?
P.S. i don't really know what should 'classpathref' be. I mean i know it should contain the classpath to the hibernate's distribution. The real problem is that I don't know how to get an Ant task working..
Edit: I figured out that the script above doesn't work with Hibernate3.. I've got another script, but still not working. The error message shown is: Could not create type hibernatetool as the class class org.hibernate.tool.ant.Hbm2JavaExporterTask has no compatible constructor; And the script:
<target name="codegen">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.Hbm2JavaExporterTask">
<classpath refid="project.classpath" />
</taskdef>
<hibernatetool destdir="cat/model/">
<configuration configurationfile="hibernate.cfg.xml"/>
<hbm2java />
</hibernatetool>
</target>
This is Hibernate3 compatible, as I saw in the hibernate docs: http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html#d0e2903
I dont know anything about hbm2java but after adding a task like in the code above, you need to add the jars associated with this to Ant. This is done by copying the jar file inton $ANT_HOME/lib
directory. Did you do this?