繁体   English   中英

如何在NetBeans中将Hbm2java任务添加到Ant

[英]How to add hbm2java task to Ant in NetBeans

我正在尝试从映射xml文件生成POJO。 我读了一些关于添加ant任务的内容,以便轻松完成。

我在下面将这个xml添加到我在Netbeans中的项目的build-impl.xml中,但没有任何反应:

<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>

我是Netbeans,Ant和Hibernate的初学者,任何人都可以帮助我吗?

PS我真的不知道'classpathref'应该是什么。 我的意思是我知道它应该包含hibernate发行版的类路径。 真正的问题是我不知道如何让Ant任务正常工作..

编辑:我发现上面的脚本不适用于Hibernate3 ..我有另一个脚本,但仍然无法正常工作。 显示的错误消息是:无法创建类型hibernatetool作为类类org.hibernate.tool.ant.Hbm2JavaExporterTask没有兼容的构造函数; 和剧本:

<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兼容的,正如我在hibernate docs中看到的那样: http//docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html#d0e2903

我对hbm2java一无所知,但在添加上述代码中的任务后,您需要将与此相关的jar添加到Ant。 这是通过复制jar文件inton $ANT_HOME/lib目录来完成的。 你做了这个了吗?

弄清楚:应该用'org.hibernate.tool.ant.HibernateToolTask​​'替换'org.hibernate.tool.ant.Hbm2JavaExporterTask'

这就是我使用它的方式。

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

</target>

您是否考虑过使用jpa注释而不是xml?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM