//User.java
在企业中model类的属性可能有几百个而且还可能继承了很多属性,这样的model如果手写映射文件岂不是很大的工程!
这里介绍Ant+XDoclet配合来自动生成映射文件。
必备:Ant和XDocle的jar包。
操作很简单,自己写一个model类例如People.java,但是要自动生成映射文件这个类需要有注释,写一个build.xml文件,
//在test目录下建立build.xml,其中<property name="xdoclet.home" value="C:/xdoclet-plugins-dist-1.0.4">为你所解压的xdoclet目录。Ant build File build.xml
-
- <project name="Hibernate Example" default="about" basedir=".">
-
- <!-- The location where your xdoclet jar files reside -->
-
- <property name="xdoclet.lib.home" value="c:/java_api/xdoclet-1.2b3/lib"/>
-
-
-
- <target name="clean" depends="init" description="removes all directories
- related to this build">
-
- <delete dir="${dist}"/>
-
- </target>
-
-
- <target name="init" description="Initializes properties that are used by
- other targets.">
- <property name="dist" value="dist"/>
- </target>
-
- <target name="prepare" depends="init,clean" description="creates dist dir
- ectory">
- <echo message="Creating required directories..."/>
- <mkdir dir="${dist}"/>
- </target>
-
- <target name="hibernate" depends="prepare"
- description="Generates Hibernate class descriptor files.">
- <taskdef name="hibernatedoclet" classname="xdoclet.
- modules.hibernate.HibernateDocletTask"> <classpath>
- <fileset dir="${xdoclet.lib.home}">
- <include name="*.jar"/>
- </fileset>
- </classpath>
- </taskdef>
-
- <!-- Execute the hibernatedoclet task -->
-
- <hibernatedoclet
- destdir="."
- excludedtags="@version,@author,@todo"
- force="true"
- verbose="true"
- mergedir="${dist}">
-
- <fileset dir=".">
- <include name="**/dbdemo/*.java"/>
- </fileset>
-
- <hibernate version="2.0"/>
-
- </hibernatedoclet>
- </target>
-
- <target name="about" description="about this build file" depends="init">
- <echo message=" Use this format for the arguments:"/>
- <echo message=" ant hibernate"/>
- <echo message=""/>
- </target>
-
- </project>
执行过程: Windows-->ShowView-->Other-->Ant文件里面(Ant)-->在Ant空白处右键-->Add Buildfiles-->选择你要生成配置文件的bulild.xml文件点击OK,让后分别执行,所要生成的文件即可.赶快试试吧...
posted on 2009-08-04 21:44
Werther 阅读(1354)
评论(0) 编辑 收藏 所属分类:
10.Java