Ant自动化构建

本文介绍了一个使用Ant进行自动化构建的实际案例,包括项目编译、测试、生成测试报告及邮件通知等流程。通过定义一系列的任务(target),实现了从源代码到测试完成的自动化过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<?xml version="1.0"?>
<project name="testAnt" basedir="." default="mail">

<!-- ========== 属性定义 ========= -->
<property name="pro.name" value="testAnt" />
<property name="pro.author" value="VS" />
<property name="src.dir" value="src/main/app" />
<property name="pro.web.root" value="WebContent" />
<property name="pro.web.source" value="${pro.web.root}/WEB-INF" />
<property name="pro.lib" value="${pro.web.source}/lib" />
<property name="pro.build.path" value="${pro.web.source}/classes" />
<property name="user.dir" value="${pro.build.path}" />

<!-- ========== 邮件发送 ========= -->
<target name="mail" depends="mkzip">
<mail mailhost="smtp.126.com" mailport="25" subject="The Build Test" user="shibanan" password="*********" messagemimetype="text/html">
<from address="shibanan@126.com" name="VS" />
<fileset dir="report/html">
<include name="**/test-result${ant.project.name}.zip" />
</fileset>
<to address="shibanan@hotmail.com" name="VS" />
<message>The ${pro.name}--${pro.author} has been tested ! </message>
</mail>
</target>

<!-- ========== 测试报告打包 ========= -->
<target name="mkzip" depends="report">
<jar destfile="report/html/test-result${ant.project.name}.zip">
<fileset dir="report/html">
<include name="**/*.html" />
<include name="**/*.css" />
<include name="**/*.txt" />
</fileset>
</jar>
</target>

<!-- ========== 生成测试报告 ========= -->
<target name="report" depends="junit">
<junitreport id="myJUnitReport" taskname="reported" todir="report" description="Junit Report">
<fileset dir="report">
<include name="TEST-*.xml" />
</fileset>
<report todir="report/html" />
</junitreport>
</target>

<!-- ========== 测试 ========= -->
<target name="junit" depends="build">
<mkdir dir="report/html" />
<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">
<formatter type="plain" usefile="false" />
<formatter type="xml" />
<test name="test.TestHelloWorld" todir="report" />
<classpath refid="classpath" />
</junit>
</target>

<!-- ========== 编译 ========= -->
<target name="build" depends="prepare">
<javac destdir="${pro.build.path}" target="1.5">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
<javac destdir="${pro.build.path}" target="1.5">
<src path="src/main/test" />
<classpath refid="classpath" />
</javac>
</target>

<!-- ========== 初始化 ========= -->
<target name="prepare" depends="clean">
<copy todir="${pro.build.path}">
<fileset dir="${src.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>

<!-- ========== 清理 ========= -->
<target name="clean">
<delete>
<fileset dir="${pro.build.path}">
<include name="**/*.*" />
</fileset>
<fileset dir="report">
<include name="**/*.*" />
</fileset>
</delete>
</target>


<path id="classpath">
<fileset dir="${pro.lib}">
<include name="*.jar" />
</fileset>
<pathelement path="${pro.build.path}" />
</path>


</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值