对于Hibernate2,要下载hibernate-extensions,把hibernate-tools.jar放入classpath中.
Ant的脚本如下:
<!-- property definition omitted -->
<taskdef name="hbm2java" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="project.class.path" />
<target name="codegen" description="Generate Java source from the O/R mapping files">
<hbm2java output="${source.root}">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml" />
</fileset>
</hbm2java>
</target>
----------------------------------------------------------
对于Hibernate3,则要下载对应的HibernateTools包,这里以HibernateTools-3.2.0.GA.zip举例.
把其中的/plugins/org.hibernate.eclipse_3.2.0.GA/lib/tools目录下:
hibernate-tools.jar 和 freemarker.jar 包copy到classpath中.
Ant的脚本如下:
<taskdef name="hbm2java" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path" />
<target name="codegen" description="Generate Java source from the O/R mapping files">
<hbm2java destdir="${source.root}">
<configuration>
<fileset dir="${source.root}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<hbm2java /><!-- this should be added to show this is a hbm2java task -->
</hbm2java>
</target>
联系客服