一个通用Build.xml模板的建立
http://www.blogjava.net/os586/archive/2006/10/18/75819.html
一、建立Web应用步骤
1、清空临时目录
2、建立目录结构
3、从vss或cvs中获得源文件
4、编译(编译java源文件、copy属性文件和xml等文件、编码转换)
5、建立WAR包
6、发布
二、建立web应用的 build.xml 模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
<?xml version="1.0"?> <!-- ======================================================================= build file ======================================================================= --> <project default="main" basedir="build"> <property name="file.war" value="myapp.war"/> <property name="dir.jdk" value="c:/jbuilderx/jdk1.4"/> <property name="dir.src" value="src"/> <property name="dir.classes" value="classes"/> <property name="dir.lib" value="lib"/> <property name="dir.web" value="web"/> <property name="vss.login" value="userId,password"/> <property name="vss.serverPath" value="i:\"/> <property name="vss.srcPath" value="/myproject/src"/> <property name="vss.libPath" value="/myproject/lib"/> <property name="vss.webPath" value="/myproject/webapp"/> <property name="server.ftp.userId" value="ftpuser"/> <property name="server.ftp.password" value="ftppassword"/> <property name="server.ftp.serverIp" value="192.168.0.1"/> <path id="project.class.path"> <pathelement location="${dir.classes}"/> <pathelement location="${dir.jdk}/jre/lib/rt.jar"/> <fileset dir="${dir.lib}"> <include name="**/*.jar"/> </fileset> </path> <target name="clean"> <delete dir="${dir.src}"/> <delete dir="${dir.classes}"/> <delete dir="${dir.lib}"/> </target> <target name="init" depends="clean"> <mkdir dir="${dir.src}"/> <mkdir dir="${dir.classes}"/> <mkdir dir="${dir.lib}"/> </target> <target name="getFromVcm" depends="init"> <vssget localPath="${dir.src}" login="${vss.login}" vsspath="${vss.srcPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> <vssget localPath="${dir.lib}" login="${vss.login}" vsspath="${vss.libPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> <vssget localPath="${dir.web}" login="${vss.login}" vsspath="${vss.webPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> </target> <target name="compile" depends="getFromVcm"> <javac bootclasspathref="project.class.path" debug="true" deprecation="true" destdir="${dir.classes}" nowarn="false" target="1.2"> <src path="${dir.src}"/> </javac> <copy todir="${dir.classes}"> <fileset dir="${dir.src}"> <include name="**/*.properties"/> <include name="**/*.xml"/> <exclude name="ApplicationResources.properties"/> </fileset> </copy> <native2ascii encoding="GBK" src="${dir.src}" dest="${dir.classes}" includes="ApplicationResources.properties"/> </target> <target name="buildWar" depends="compile"> <war destfile="${file.war}" webxml="${dir.web}/WEB-INF/web.xml"> <lib dir="${dir.lib}"/> <classes dir="${dir.classes}"/> <fileset dir="${dir.web}"/> </war> </target> <target name="deploy" depends="buildWar"> <ftp server="${server.ftp.serverIp}" userid="${server.ftp.userId}" password="${server.ftp.password}"> <fileset dir="."> <include name="${file.war}"/> </fileset> </ftp> </target> <target name="main" description="" depends="deploy"/> </project> |
ant集成junit自动测试的build.xml标准模板
http://liyuandong.iteye.com/blog/964027
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wallacer/archive/2006/07/26/982130.aspx
利用Ant集成Junit自动测试并生成测试报告,可以极大的提高测试的工作效率,其优势只要是测试用例的批量处理功能。前不久在网上看到很多关于Junit测试的文章,欣闻Ant支持Junit的集成,迫不及待的尝试了一番。
1. ant的配置:
本案例采用apache-ant-1.6.5版本,下载ant后需要将Junit3.8.1拷贝到ANT_HOME的lib目录下。Ant在执行过程TestCase过程中除了需要在classpath中可见,还需要在ant中可见,否则会报错。
2. 目录结构:
工作目录
|-src-|—com-|—wallace-|-Calculator.java
|-test-|-TestCalculator.java
|-lib-|-junit.jar
|-build
|-report
3. build.xml模板:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
<?xml version="1.0" encoding="utf-8"?> <project name="test" default="test" basedir="."> <!--配置基本属性--> <property name="src" value="src"/> <property name="build" value="build"/> <property name="lib" value="lib" /> <property name="dist" value="dist"/> <property name="classpath" location="${build}"/> <!--配置测试报告的属性--> <property name="report" value="report"/> <property name="report.xml" value="${report}/junit/xml"/> <property name="report.html" value="${report}/junit/html"/> <!--配置运行时classpath--> <path id="classpath.run"> <pathelement path="${classpath}"/> <fileset dir="${lib}"> <include name="*.jar"/> </fileset> </path> <!--配置测试时classpath--> <path id="classpath.test"> <path refid="classpath.run"/> <path location="${dist}/lib/test-${DSTAMP}.jar"/> </path> <!--任务初始化--> <target name="init" > <tstamp/> <delete dir="${build}"/> <delete dir="${report}"/> <delete dir="${dist}"/> <mkdir dir="${build}"/> </target> <!--配置编译任务--> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}"> <classpath refid="classpath.run" /> </javac> </target> <!--配置打包任务--> <target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/test-${DSTAMP}.jar" basedir="${build}"/> </target> <!--配置运行任务--> <target name="run" depends="compile, dist"> <java classname="com.test.TestCalculator"> <classpath> <path refid="classpath.run"/> </classpath> </java> </target> <!--配置JUnit测试,打印测试结果--> <target name="test" depends="compile, dist"> <mkdir dir="${report.xml}"/> <mkdir dir="${report.html}"/> <junit printsummary="yes" haltonfailure="no"> <classpath refid="classpath.run"/> <formatter type="xml"/> <batchtest fork="yes" todir="${report.xml}"> <fileset dir="${src}" includes="**/Test*.java"/> </batchtest> </junit> <junitreport todir="${report.html}"> <fileset dir="${report.xml}"> <include name="*.xml"/> </fileset> <report format="frames" todir="${report.html}"/> </junitreport> </target> </project> |
模板三:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<?xml version="1.0"?> <project name="Hello world" default="doc"> <!-- properies --> <property name="src.dir" value="WEB-INF/src" /> <property name="report.dir" value="report" /> <property name="classes.dir" value="WEB-INF/classes" /> <property name="lib.dir" value="WEB-INF/lib" /> <property name="dist.dir" value="dist" /> <property name="doc.dir" value="doc" /> <!-- 定义classpath --> <path id="master-classpath"> <fileset file="${lib.dir}/*.jar" /> <pathelement path="${classes.dir}" /> </path> <!-- 初始化任务--> <target name="init"> </target> <!-- 编译--> <target name="compile" depends="init" description="compile the source files"> <mkdir dir="${classes.dir}" /> <javac srcdir="${src.dir}" destdir="${classes.dir}" target="6.0"> <classpath refid="master-classpath" /> </javac> </target> <!-- 测试 --> <target name="test" depends="compile" description="run junit test"> <mkdir dir="${report.dir}" /> <junit printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true"> <classpath refid="master-classpath" /> <formatter type="plain" /> <batchtest todir="${report.dir}"> <fileset dir="${classes.dir}"> <include name="**/*Test.*" /> </fileset> </batchtest> </junit> <fail if="tests.failed"> </fail> </target> <!-- 打包成jar --> <target name="jar" description="make .jar file"> <mkdir dir="${dist.dir}" /> <jar destfile="${dist.dir}/hello.jar" basedir="${classes.dir}"> <exclude name="**/*Test.*" /> <exclude name="**/Test*.*" /> </jar> </target> <!-- 将项目打包成war--> <target name="war" depends="jar"> <war destfile="${basedir}/myApp.war" webxml="${basedir}/WEB-INF/web.xml"> <!--包含文件夹下所有内容--> <fileset dir="${basedir}" casesensitive="yes" id="id"> <include name="WEB-INF/**" /> <exclude name="*.war" /> </fileset> <lib dir="${lib.dir}"> <include name="*.jar" /> </lib> </war> </target> <!-- 输出api文档 --> <target name="doc" depends="jar" description="create api doc"> <mkdir dir="${doc.dir}" /> <javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="Test API"> <packageset dir="${src.dir}" defaultexcludes="yes"> <include name="example/**" /> </packageset> <doctitle> <![CDATA[<h1>Hello, test</h1>]]></doctitle> <bottom> <![CDATA[<i>All Rights Reserved.</i>]]></bottom> <tag name="todo" scope="all" description="To do:" /> </javadoc> </target> </project> |