對(duì)于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>
----------------------------------------------------------
對(duì)于Hibernate3,則要下載對(duì)應(yīng)的HibernateTools包,這里以HibernateTools-3.2.0.GA.zip舉例. 把其中的/plugins/org.hibernate.eclipse_3.2.0.GA/lib/tools目錄下: hibernate-tools.jar 和 freemarker.jar 包c(diǎn)opy到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>
|