只需要一个POJO产生所需的所有配置和文件。
● build.xml文件分析
Ø 功能说明
该工具主要完成
i) 利用XDoclet自动产生文件
ii) 配置Spring
iii) 配置资源文件
iv) 配置数据库测试数据
v) 将生成的文件拷贝到主项目中
Ø 执行过程
ant install -Dmodel.name=Person -Dmodel.name.lowercase=per son
Ø build.xml文件分析
<project name="appgen" default="default">
<!--D:\Documents and Settings\Administrator/appgen-build.properties-->
<property file="${user.home}/${ant.project.name}-build.properties"/>
<!--D:\Documents and Settings\Administrator/build.properties-->
<property file="${user.home}/build.properties"/>
<!--e:/dudu/build.properties-->
<property file="../../build.properties"/>
<!--e:/dudu/lib-->
<property name="lib.dir" location="../../lib"/>
<!--e:/dudu/lib/lib.properties-->
<property file="${lib.dir}/lib.properties"/>
<!—e:/dudu/src/dao-->
<property name="model.src.dir" location="../../src/dao"/>
<property name="gen.dir" value="gen"/>
<property name="app.package" value="org/dudu"/>
<!—该任务没什么用处,只是编译样例类FormTagsHandler.java等-->
<target name="compile" depends="init">
<mkdir dir="${build.dir}"/>
<javac srcdir="src"
destdir="${build.dir}"
debug="${javac.debug}"
classpathref="xdoclet.classpath"/>
</target>
<!—利用XDoclet自动产生文件-->
<target name="gen" depends="compile">
<taskdef name="xdoclet" classname="xdoclet.DocletTask">
<classpath>
<path refid="xdoclet.classpath"/>
<pathelement location="${build.dir}"/>
</classpath>
</taskdef>
<property name="template.dir" value="src"/>
<!-- build.dir =E:\dudu\extras\appgen/build-->
<xdoclet destdir="${build.dir}"
excludedtags="@version,@author"
force="${xdoclet.force}">
<!—处理e:/dudu/src/dao目录下的类-->
<fileset dir="${model.src.dir}" includes="**/${model.name}.java"/>
<!—以下为更加XDoclet模板生成所需文件-->
<!-- DAO Test -->
<template templateFile="${template.dir}/detailed/DAOTest.xdt"
acceptAbstractClasses="false"
prefixWithPackageStructure="false"
destinationFile="${gen.dir}/test/dao/${app.package}/dao/PersonDAOTest.java"/>
… …
</target>
<target name="install-src-detailed">
<!—将所有的java文件拷贝到主项目中,拷贝metadata、src、test、web目录中java
的文件。
配置Spring,为bean添加Spring配置,根据
${generated.dir}/src/dao/${app.package}/dao/hibernate/context-hibernate-${
model.name}.xml"文件内容修
改../../src/dao/${app.package}/dao/hibernate/applicationContext-hibernate.
xml 配置
${generated.dir}/src/service/${app.package}/service/context-service-${mode
l.name}.xml 文件-->
</target>
<target name="install-other">
<!—该任务主要完成合并常量到Constants.java -->
<!—合并数据库测试数据到sample-data.xml -->
<!—合并测试数据到web-tests.xml -->
<!—为ApplicationResources_en.properties增加属性值-->
<!—copy From.jsp和FormList.jsp文件到主项目-->
<!—修改菜单项-->
</target>
<target name="install-src-generic">
<!—该任务将Struts Action类和ActionTest类拷贝到主项目中-->
</target>
<target name="install" depends="install-src-generic,install-other"
description="Generates generic code and copies into main project">
<echo>Installation completed successfully!</echo>
</target>
</project>
Ø AppGen生成19个文件,文件列表如下:
[echo] gen file=gen/test/dao/org/dudu/dao/PersonDAOTest.java
[echo] gen file=gen/src/dao/org/dudu/dao/PersonDAO.java
[echo] gen file=gen/src/dao/org/dudu/dao/hibernate/PersonDAOHibernate.java
[echo] gen file=gen/src/dao/org/dudu/dao/hibernate/context-hibernate-Person.xml
[echo] gen file=gen/test/service/org/dudu/service/PersonManagerTest.java
[echo] gen file=gen/src/service/org/dudu/service/PersonManager.java
[echo] gen file=gen/src/service/org/dudu/service/impl/PersonManagerImpl.java
[echo] gen file=gen/src/service/org/dudu/service/context-service-Person.xml
[echo] gen file=gen/src/dao/org/dudu/Constants-Person.java
[echo] gen file=gen/test/web/org/dudu/webapp/action/PersonActionTest.java
[echo] gen file=gen/src/web/org/dudu/webapp/action/PersonAction.java
[echo] gen file=gen/generic/src/web/org/dudu/webapp/action/PersonAction.java
[echo] gen file=gen/metadata/sql/sample-data-Person.xml
[echo] gen file=gen/test/web/web-tests-Person.xml
[echo] gen file=gen/web/WEB-INF/classes/Person.properties
[echo] gen file=gen/web/pages/PersonForm.jsp
[echo] gen file=gen/web/pages/PersonList.jsp
[echo] gen file=gen/web/WEB-INF/menu-config-Person.xml
[echo] gen file=gen/web/pages/menu-Person.jsp
注:为了实现生成文件后的拷贝工作:\duducms\extras\appgen\build.xml
<target name="install-src-generic">
<!—添加如下内容-->
<copy todir="../../src" overwrite="${overwrite}">
<fileset dir="${generated.dir}/src" includes="**/*.java"/>
</copy>
… …
</target>