js 代码
- <?xml version="1.0"?>
- <project name="springproj" basedir="." default="mail">
- <property name="pro.name" value="springproj" />
- <property name="pro.author" value="Danlley Wei" />
- <property name="src.dir" value="src/main/java" />
- <property name="pro.web.root" value="war" />
- <property name="pro.web.source" value="${pro.web.root}/WEB-INF" />
- <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="用户名" password="邮箱密码">
- <from address="发送地址" name="Danlley Wei" />
- <fileset dir="report/html">
- <include name="**/test-result${ant.project.name}.zip" />
- </fileset>
- <to address="邮件接收地址" name="Danlley Wei" />
- <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" haltοnerrοr="yes" haltonfailure="yes" fork="yes">
- <formatter type="plain" usefile="false" />
- <formatter type="xml" />
- <test name="org.danlley.hibernate.dao.DeptDAOImplTest" todir="report" />
- <classpath refid="master-classpath" />
- </junit>
- </target>
- <target name="build" depends="prepare">
- <javac destdir="${pro.build.path}" target="1.5">
- <src path="${src.dir}" />
- <classpath refid="master-classpath" />
- </javac>
- <javac destdir="${pro.build.path}" target="1.5">
- <src path="src/main/test" />
- <classpath refid="master-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="master-classpath">
- <fileset dir="lib">
- <include name="*.jar" />
- </fileset>
- <pathelement path="${pro.build.path}" />
- </path>
- </project>
target依赖关系:
mail→mkzip→report→junit→build→prepare→clean
工程classpath:master-classpath
clean节点: 删除测试和编译过程中生成的所有文件 prepare节点: 将工程编译打包所需资源文件全部拷贝到编译路径下 build节点: 生成工程源文件和测试代码源文件的二进制版本 junit节点: 运行测试用例 report节点: 生成测试报告 mkzip节点: 将生成的测试报告以zip格式进行打包 mail节点: 将测试结果发送到开发小组邮箱
1. 我在模板 中使用的126邮箱,如果你的邮箱是新申请的126邮箱,上述模板可能没办法发送你的邮件,原因是126邮箱对于新申请的用户暂时不开通smtp和pop3服务 2.ant并不会自带安装发送邮件所需相关资源包,因此需要我们手动到sun官方网站下载,然后把资源包放到ant的lib下面,我的位置是:D:\apache-ant-1.7.0\lib 可以从下面地址下载ant发邮件所需的两个资源(mail.jar和activation.jar): http://java.sun.com/products/javamail http://java.sun.com/products/javabeans/glasgow/jaf.html