v db-load: 把示例数据加载到数据库中
Ø 任务定义:
<target name="db-load" depends="prepare"
description="Loads the database with sample data">
<property name="operation" value="CLEAN_INSERT"/>
<property name="file" value="metadata/sql/sample-data.xml"/>
<dbunit driver="${database.driver_class}"
supportBatchStatement="false"
url="${database.url}"
userid="${database.username}"
password="${database.password}">
<operation type="${operation}" src="${file}" format="xml"/>
</dbunit>
</target>
Ø 运行结果:
[dbunit] Executing operation: CLEAN_INSERT
[dbunit] on file: E:\app\appfuse\metadata\sql\sample-data.xml
[dbunit] with format: xml
(connection.DriverManagerConnectionProvider 143 ) cleaning up connection pool: jdbc:mysql://localhost/appfuse?autoReconnect=true&useUnicode=true&characterEncoding=utf-8
v setup-tomcat: copies jdbc driver and context.xml to tomcat
Ø 运行结果:
[echo] Detected Tomcat 5...
[echo] Copying appfuse.xml...
[copy] Copying 1 file to E:\tomcat\conf\Catalina\localhost
[echo] Copying mysql JDBC Driver...
[copy] Copying 1 file to E:\tomcat\common\lib
[echo] Copying jta.jar...
v compile-service:编译service下的类
Ø 运行结果:
compile-module:
[echo] Compiling service...
[mkdir] Created dir: E:\app\appfuse\build\service\classes
[mkdir] Created dir: E:\app\appfuse\build\test\service\classes
[javac] Compiling 16 source files to E:\app\appfuse\build\service\classes
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] Compiling 7 source files to E:\app\appfuse\build\test\service\classes
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
v package-service:打包service
Ø 运行结果:
[jar] Building jar: E:\app\appfuse\dist\appfuse-service.jar
v copy-resources: 拷贝应用需要的各种配置文件到build\web\classes和
build\appfuse\WEB-INF,而且在此任务中会进行中文转换码工作,借助JDK的native2ascii工具将资源文件ApplicationResources_zh_CN.properties中的内容进行转码。
Ø 任务定义:
<target name="copy-resources" depends="prepare"
description="Copy .properties and .xml files from source directory">
<copy todir="${build.dir}/web/classes" includeEmptyDirs="no">
<fileset dir="web/WEB-INF/classes">
<exclude name="ApplicationResources_zh_CN.properties"/>
<include name="*.properties"/>
<include name="*.xml"/>
<include name="*.vm"/>
</fileset>
<filterset refid="variables.to.replace"/>
</copy>
<native2ascii src="web/WEB-INF/classes" dest="${build.dir}/web/classes"
includes="ApplicationResources_zh_CN.properties" encoding="UTF-8"/>
<!-- Copy Spring configuration files -->
<copy overwrite="true"
tofile="${webapp.target}/WEB-INF/applicationContext-${dao.type}.xml">
<fileset dir="src/dao" includes="**/*-${dao.type}.xml"/>
<filterset refid="variables.to.replace"/>
</copy>
<copy
tofile="${webapp.target}/WEB-INF/applicationContext-service.xml">
<fileset dir="src/service" includes="**/*-service.xml"/>
</copy>
<antcall target="generate.database.properties"/>
<copy todir="${build.dir}/web/classes" file="database.properties"/>
</target>
Ø 运行结果:
[copy] Copying 10 files to E:\app\appfuse\build\web\classes
[native2ascii] Converting 1 file from E:\app\appfuse\web\WEB-INF\classes to E:\app\appfuse\build\web\classes
[copy] Copying 1 file to E:\app\appfuse\build\appfuse\WEB-INF
[copy] Copying 1 file to E:\app\appfuse\build\appfuse\WEB-INF
v copy-web-files:
Ø 任务定义:
<target name="copy-web-files" depends="prepare"
description="Copy static files">
<echo message="Copying static files"/>
<copy todir="${webapp.target}" includeEmptyDirs="no">
<fileset dir="${basedir}/web">
<include name="**"/>
<exclude name="common/footer.jsp"/>
<exclude name="pages/**"/>
<exclude name="**/classes/**"/>
<exclude name="**/*-resources.xml"/>
</fileset>
</copy>
<!-- Remove the copy block below if you're not displaying
version/copyright in the footer -->
<copy todir="${webapp.target}">
<fileset dir="web" includes="common/footer.jsp"/>
<filterset>
<filter token="APPVERSION" value="${webapp.version}"/>
<filter token="COPYRIGHT-YEAR" value="${copyright.year}"/>
</filterset>
</copy>
<!-- Copy JSP Pages under WEB-INF/pages -->
<copy todir="${webapp.target}/WEB-INF">
<fileset dir="${basedir}/web">
<include name="pages/**/*.jsp"/>
</fileset>
</copy>
<!-- Copy *.txt files so they can be included in release notes -->
<copy todir="${webapp.target}">
<fileset dir="${basedir}">
<include name="*.txt"/>
<exclude name="README-new.txt"/>
</fileset>
</copy>
</target>
Ø 运行结果:
[echo] Copying static files
[copy] Copying 64 files to E:\app\appfuse\build\appfuse
[copy] Copying 1 file to E:\app\appfuse\build\appfuse
[copy] Copying 12 files to E:\app\appfuse\build\appfuse\WEB-INF
[copy] Copying 2 files to E:\app\appfuse\build\appfuse
v gen-forms: 利用xdoclet 和struts_form.xdt,根据module目录中的POJO生成
Struts的ActionFrom
Ø 任务定义:
<!-- Generate ActionForms from POJOs -->
<target name="gen-forms" depends="prepare" unless="webdoclet.uptodate"
description="Generates ActionForms from POJOs">
<taskdef name="xdoclet" classname="xdoclet.DocletTask"
classpathref="xdoclet.classpath"/>
<!-- generate struts forms -->
<xdoclet destdir="${build.dir}/web/gen"
excludedtags="@version,@author"
addedtags="@xdoclet-generated at ${TODAY}"
force="${xdoclet.force}"
mergedir="metadata/web">
<fileset dir="src/dao"/>
<!-- generate struts forms -->
<actionform templateFile="metadata/templates/struts_form.xdt">
<packageSubstitution packages="model"
substituteWith="webapp.form"/>
</actionform>
</xdoclet>
</target>
Ø 运行结果:
[xdoclet] (XDocletMain.start 47 ) Running <actionform/>
[xdoclet] --> UserForm
[xdoclet] --> RoleForm
[xdoclet] --> AddressForm
v compile-web:编译web目录中的类,appfuse中的web服务类是不被打包成jar文件的,
直接放在WEB-INF/class目录下调用。
Ø 运行结果:
compile-module:
[echo] Compiling web...
[mkdir] Created dir: E:\app\appfuse\build\test\web\classes
[javac] Compiling 28 source files to E:\app\appfuse\build\web\classes
v webdoclet:利用xdoclet.modules.web.WebDocletTask工具,生成了web.xml、
appfuse.tld、struts-config.xml 、struts_config_xml.xdt 、validation.xml 、
validation_xml.xdt等文件
Ø 任务定义:
<!-- =================================================================== -->
<!-- The "webdoclet" target generates web and struts deployment -->
<!-- descriptors. -->
<!-- =================================================================== -->
<target name="webdoclet" depends="compile-web"
unless="webdoclet.unnecessary"
description="Generate web and Struts descriptors">
<taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask">
<classpath>
<path refid="xdoclet.classpath"/>
<path refid="web.compile.classpath"/>
</classpath>
</taskdef>
<webdoclet destdir="${webapp.target}/WEB-INF"
force="${xdoclet.force}"
mergedir="metadata/web"
excludedtags="@version,@author"
verbose="true">
<fileset dir="src/web"/>
<fileset dir="${build.dir}/web/gen"/>
<deploymentdescriptor validateXML="true"
servletspec="2.3" sessiontimeout="10"
destdir="${webapp.target}/WEB-INF" distributable="false"
displayname="${ant.project.name}">
<configParam name="httpPort" value="${http.port}"/>
<configParam name="httpsPort" value="${https.port}"/>
<configParam name="daoType" value="${dao.type}"/>
<configParam name="security" value="${security.mode}"/>
</deploymentdescriptor>
<jsptaglib validateXML="true"
description="Custom tag library for this application"
shortName="${webapp.name}" filename="${webapp.name}.tld"/>
<strutsconfigxml validateXML="true" version="1.2"/>
<strutsvalidationxml/>
</webdoclet>
</target>
Ø 运行结果:
[webdoclet] (XDocletMain.start 47 ) Running <deploymentdescriptor/>
[webdoclet] Generating web.xml.
[webdoclet] (XDocletMain.start 47 ) Running <jsptaglib/>
[webdoclet] Generating appfuse.tld.
[webdoclet] (XDocletMain.start 47 ) Running <strutsconfigxml/>
[webdoclet] (TemplateSubTask.engineStarted 805 ) Generating output 'struts-config.xml' using template file 'jar:file:E:\app\appfuse\lib\xdoclet-1.2.2\lib\xdoclet-apache-module-1.2.2.jar!/xdoclet/modules/apache/struts/resources/struts_config_xml.xdt'.
[webdoclet] (XDocletMain.start 47 ) Running <strutsvalidationxml/>
[webdoclet] (TemplateSubTask.engineStarted 805 ) Generating output 'validation.xml' using template file 'jar:file:E:\app\appfuse\lib\xdoclet-1.2.2\lib\xdoclet-apache-module-1.2.2.jar!/xdoclet/modules/apache/struts/resources/validation_xml.xdt'.
v package-web:打包部署文件war
Ø 任务定义:
<target name="package-web" depends="compile-web,jsp-2"
description="Package WAR">
<propertyfile comment="Build Information"
file="${build.dir}/web/classes/build.properties">
<entry key="build.date" type="date" pattern="EEEE MMM dd, yyyy"
value="now"/>
<entry key="build.time" type="date" pattern="hh:mm:ss a zz"
value="now"/>
<entry key="build.username" value="${user.name}"/>
<entry key="build.computer" value="${env.COMPUTERNAME}"/>
<entry key="build.dao.type" value="${dao.type}"/>
<entry key="webapp.version" value="${webapp.version}"/>
</propertyfile>
<!-- If Tomcat 5, uncomment the <dispatcher> elements in
filter-mappings -->
<if>
<or>
<isset property="tomcat5"/>
<isset property="tomcat5.5"/>
</or>
<then>
<replaceregexp flags="g"
file="${webapp.target}/WEB-INF/web.xml"
match='<!--dispatcher>'
replace='<dispatcher>'/>
<replaceregexp flags="g"
file="${webapp.target}/WEB-INF/web.xml"
match='</dispatcher-->'
replace='</dispatcher>'/>
</then>
</if>
<echo>Preparing tomcat-context.xml for inclusion in war</echo>
<!-- Copy tomcat-context.xml file to context.xml -->
<if>
<and>
<isset property="tomcat5"/>
<not><isset property="tomcat5.5"/></not>
</and>
<then>
<copy tofile="${webapp.dist}/context.xml"
file="metadata/conf/tomcat-context.xml" overwrite="true">
<filterset refid="db.variables"/>
</copy>
</then>
<elseif>
<isset property="tomcat5.5"/>
<then>
<copy tofile="${webapp.dist}/context.xml"
file="metadata/conf/tomcat-context-5.5.xml" overwrite="true">
<filterset refid="db.variables"/>
</copy>
</then>
</elseif>
</if>
<!-- Change the path so webapp can find .hbm in appfuse-dao.jar -->
<replace file="${webapp.target}/WEB-INF/applicationContext-${dao.type}.xml">
<replacetoken>file:dist</replacetoken>
<replacevalue>WEB-INF/lib</replacevalue>
</replace>
<!-- Copy .properties files in src tree to build/web/classes -->
<copy todir="${build.dir}/web/classes">
<fileset dir="src/web">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<war destfile="${webapp.dist}/${webapp.war}"
webxml="${webapp.target}/WEB-INF/web.xml" compress="true">
<fileset dir="${webapp.target}" excludes="**/web.xml,**/*-resources.xml"/>
<metainf dir="${webapp.dist}" includes="context.xml"/>
<classes dir="${build.dir}/web/classes">
<exclude name="**/database.properties"/>
</classes>
<lib file="${dist.dir}/${webapp.name}-dao.jar"/>
<lib file="${dist.dir}/${webapp.name}-service.jar"/>
<webinf dir="${struts.dir}" includes="*.xml"/>
<webinf dir="web/WEB-INF" includes="*-resources.xml"/>
<lib file="${clickstream.jar}"/>
<lib dir="${struts.dir}" includes="*.jar"/>
<lib dir="${jstl.dir}/lib">
<include name="jstl.jar"/>
<include name="standard.jar"/>
</lib>
<lib dir="${javamail.dir}" includes="*.jar"/>
<lib file="${log4j.jar}"/>
<lib file="${strutsmenu.jar}"/>
<lib dir="${displaytag.dir}" includes="*.jar"/>
<lib file="${hibernate.jar}"/>
<lib dir="${hibernate.dir}/lib">
<include name="odmg*.jar"/>
<include name="dom4j*.jar"/>
<include name="cglib*.jar"/>
<include name="ehcache*.jar"/>
<include name="oscache*.jar"/>
</lib>
<lib dir="${spring.dir}" includes="*.jar"/>
<lib file="${sitemesh.jar}"/>
<lib dir="${velocity.dir}" includes="*.jar"/>
<lib file="${urlrewrite.jar}"/>
</war>
</target>
Ø 运行结果:
[propertyfile] Creating new property file: E:\app\appfuse\build\web\classes\build.properties
[echo] Preparing tomcat-context.xml for inclusion in war
[copy] Copying 1 file to E:\app\appfuse\dist\webapps
[copy] Copying 1 file to E:\app\appfuse\build\web\classes
[war] Building war: E:\app\appfuse\dist\webapps\appfuse.war
v deploy:部署应用
Ø 运行结果:
[unwar] Expanding: E:\app\appfuse\dist\webapps\appfuse.war into E:\tomcat\webapps\appfuse
setup:
BUILD SUCCESSFUL
Total time: 10 minutes 38 seconds