How to add hbm2java task to Ant in NetBeans

I am trying to create a POJO to map xml files. I read something about adding an ant task to make this easy.

I added this xml below to my build-impl.xml project 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 new to Netbeans, ant and Hibernate, can anyone help me?

PS I really don't know what classpathref should be. I mean, I know that it should contain the path to the hibernate class. The real problem is that I do not know how to get the ant working.

: , script Hibernate3. script, . : hibernatetool org.hibernate.tool.ant.Hbm2JavaExporterTask ; 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>

Hibernate3, : http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html#d0e2903

+3
4

hbm2java, , , , , Ant. inton $ANT_HOME/lib jar. ?

+1

: "org.hibernate.tool.ant.Hbm2JavaExporterTask" "org.hibernate.tool.ant.HibernateToolTask"

+1

This is how I use it.     

    <hibernatetool destdir="${src.java.dir}">
        <configuration>
            <fileset dir="${src.java.dir}">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </configuration>
        <hbm2java/> <!-- Generate POJO source -->
    </hibernatetool>

</target>
0
source

Have you considered using jpa annotations instead of xml?

0
source

Source: https://habr.com/ru/post/1734807/


All Articles