我试图通过映射xml文件来生成POJO。我读到了一些关于添加蚂蚁任务的文章,以方便地完成它。
我已经在下面的Netbeans中将这个xml添加到我的项目的buil-inst.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的初学者,有人能帮我吗?
我不知道什么应该是“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文档中看到的:http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html#d0e2903
发布于 2010-03-01 00:19:16
我对hbm2java一无所知,但是在添加了上面代码中的任务之后,您需要将与此相关的jars添加到Ant中。这是通过复制jar文件inton $ANT_HOME/lib目录来完成的。是你干的吗?
发布于 2010-03-01 08:42:43
应将“org.hibernate.tool.ant.Hbm2JavaExporterTask”改为“org.hibernate.tool.ant.HibernateToolTask”
发布于 2010-11-15 20:48:19
我就是这么用的。
<hibernatetool destdir="${src.java.dir}">
<configuration>
<fileset dir="${src.java.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/> <!-- Generate POJO source -->
</hibernatetool>
</target>https://stackoverflow.com/questions/2353145
复制相似问题