我的Antfile模板
版权声明:本文可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者署名及本版权声明。
下午有点时间,整理了一下最近几个项目使用的Antfile,并参考了spring源代码中Antfile的格式,形成一个模板,以后就套用这个了。
不过还是更习惯使用Makefile的格式,xml看多了真是头晕~
[文件头]
1 2 | <?xml version="1.0" encoding="UTF-8"?> <project name="filemanager" basedir="." default="help"> |
[说明]
4 5 6 7 8 9 10 11 | <!-- ============================== --> <!-- 说明 --> <!-- ============================== --> <description> ROBERTBAO - http://www.robertbao.com Copyright (C) 2006-2010 robertbao.com @Author: robertbao </description> |
[环境变量]
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <!-- ============================== --> <!-- 环境变量 --> <!-- ============================== --> <property name="app.name" value="filemanager" /> <property name="src.dir" value="${basedir}/src/" /> <property name="bin.dir" value="${basedir}/WebContent/WEB-INF/classes" /> <property name="lib.dir" value="${basedir}/WebContent/WEB-INF/lib" /> <property name="war.dir" value="${basedir}/war" /> <property name="doc.dir" value="${basedir}/javadoc" /> <property name="db.dir" value="${basedir}/db" /> <property name="junitreport.dir" value="${basedir}/junitreport" /> <property name="junitxml.dir" value="${junitreport.dir}/xml" /> <property name="junithtml.dir" value="${junitreport.dir}/html" /> <property name="cobertura.dir" value="${basedir}/cobertura" /> <property name="instrumented.dir" value="${cobertura.dir}/classes" /> <property name="db.driver" value="com.mysql.jdbc.Driver" /> <property name="db.url" value="jdbc:mysql://localhost:3306/${app.name}" /> <property name="db.user" value="robertbao" /> <property name="db.pw" value="robertbao123" /> |
[类加载路径]
35 36 37 38 39 40 41 42 43 44 45 | <!-- ============================== --> <!-- 类加载路径 --> <!-- ============================== --> <path id="classpath"> <pathelement location="${basedir}" /> <pathelement location="${basedir}/WebContent/WEB-INF" /> <pathelement location="${basedir}/WebContent/WEB-INF/classes" /> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> </path> |
[帮助]
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 | <!-- ============================== --> <!-- 帮助 --> <!-- ============================== --> <target name="help"> <echo message="" /> <echo message="${app.name} build file" /> <echo message="------------------------------------------------------" /> <echo message="" /> <echo message="Available targets are:" /> <echo message="" /> <echo message="clean --> Clean output dir" /> <echo message="build --> Compile main Java sources and copy libraries" /> <echo message="javadoc --> Create complete Javadoc documentation" /> <echo message="warfile --> Build the web application archive" /> <echo message="setup-db --> Initialize the database" /> <echo message="junit-test --> Junit test" /> <echo message="cobertura-test --> cobertura test" /> <echo message="cobertura-check --> cobertura check" /> <echo message="junit-report --> Junit report" /> <echo message="cobertura-report --> cobertura report" /> <echo message="report --> Gen report" /> <echo message="run --> Run main class" /> <echo message="jar --> Build jar" /> <echo message="all --> Clean, build, javadoc, warfile, test" /> <echo message="clean-ibatis --> Clean ibatis dir" /> <echo message="zip --> Zip something" /> <echo message="mail --> Mail something" /> <echo message="" /> </target> |
[清理环境]
77 78 79 80 81 82 83 | <!-- ============================== --> <!-- 清理环境 --> <!-- ============================== --> <target name="clean" description="Clean output dirs (build, docs, testbuild, testreports, weblib, dist)"> <delete dir="${bin.dir}" /> <delete dir="${war.dir}" /> </target> |
[编译]
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | <!-- ============================== --> <!-- 编译 --> <!-- ============================== --> <target name="build" description="Compile main source tree java files into class files, generate jar files"> <mkdir dir="${bin.dir}" /> <javac destdir="${bin.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"> <src path="${src.dir}" /> <compilerarg line="-encoding UTF-8" /> <classpath refid="classpath"> </classpath> </javac> <copy todir="${bin.dir}" preservelastmodified="true"> <fileset dir="${src.dir}"> <include name="**/*.xml" /> <include name="**/*.properties" /> </fileset> </copy> </target> |
[生成javadoc]
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | <!-- ============================== --> <!-- 生成javadoc --> <!-- ============================== --> <target name="javadoc" description="Create complete Javadoc documentation"> <delete dir="${doc.dir}" /> <mkdir dir="${doc.dir}" /> <javadoc sourcepath="${src.dir}" destdir="${doc.dir}" windowtitle="${app.name}" source="1.5" author="true" version="true" use="true" packagenames="*"> <doctitle> <h1>${app.name}</h1> </doctitle> <bottom> <i>robertbao, 2006-2010.</i> </bottom> <classpath refid="classpath" /> </javadoc> </target> |
[打war包]
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | <!-- ============================== --> <!-- 打war包 --> <!-- ============================== --> <target name="warfile" description="Build the web application archive"> <mkdir dir="${war.dir}" /> <war warfile="${war.dir}/${app.name}.war" basedir="${war.dir}" webxml="${war.dir}/WEB-INF/web.xml"> <include name="*" /> <include name="docs/**" /> <include name="html/**" /> <include name="styles/**" /> <include name="images/**" /> <include name="WEB-INF/*.*" /> <exclude name="WEB-INF/web.xml" /> <include name="WEB-INF/classes/*.*" /> <include name="WEB-INF/lib/**" /> <include name="WEB-INF/jsp/**" /> <include name="WEB-INF/classes/META-INF/*" /> <include name="META-INF/*" /> <exclude name="**/.*" /> </war> </target> |
[数据库创建表]
143 144 145 146 147 148 149 150 151 152 153 154 155 156 | <!-- ============================== --> <!-- 数据库创建表 --> <!-- ============================== --> <target name="db-create-table" if="useMYSQL"> <echo message="Creating tables using: ${db.driver} ${db.url}" /> <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue"> <classpath> <fileset dir="${db.dir}/mysql"> <include name="mysql*.jar" /> </fileset> </classpath> <transaction src="${db.dir}/create-table.sql" /> </sql> </target> |
[数据库插入表]
158 159 160 161 162 163 164 165 166 167 168 169 170 171 | <!-- ============================== --> <!-- 数据库插入表 --> <!-- ============================== --> <target name="db-insert-table"> <echo message="Populating tables using: ${db.driver} ${db.url}" /> <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}"> <classpath> <fileset dir="${db.dir}/mysql"> <include name="mysql*.jar" /> </fileset> </classpath> <transaction src="${db.dir}/insert-table.sql" /> </sql> </target> |
[创建数据库环境]
173 174 175 176 177 | <!-- ============================== --> <!-- 创建数据库环境 --> <!-- ============================== --> <target name="setup-db" depends="db-create-table,db-insert-table" description="Initialize the selected database"> </target> |
[junit单元测试]
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | <!-- ============================== --> <!-- junit单元测试 --> <!-- ============================== --> <target name="junit-test" description="Run tests using initialized database"> <delete dir="${junitxml.dir}" /> <mkdir dir="${junitxml.dir}" /> <junit forkmode="perBatch" printsummary="true" haltonfailure="no" haltonerror="no"> <classpath path="${bin.dir}" /> <classpath refid="classpath" /> <formatter type="xml" /> <batchtest fork="yes" todir="${junitxml.dir}"> <fileset dir="${bin.dir}"> <include name="**/*ActionTest.class" /> <exclude name="**/BaseActionTest.class" /> <exclude name="**/*SuiteTests.class" /> </fileset> </batchtest> </junit> </target> |
[cobertura任务定义]
199 200 201 202 | <!-- ============================== --> <!-- cobertura任务定义 --> <!-- ============================== --> <taskdef classpathref="classpath" resource="tasks.properties" /> |
[cobertura准备]
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | <!-- ============================== --> <!-- cobertura准备 --> <!-- ============================== --> <target name="cobertura-instrument"> <delete dir="${instrumented.dir}" /> <mkdir dir="${instrumented.dir}" /> <delete file="${basedir}/cobertura.ser"/> <cobertura-instrument todir="${instrumented.dir}"> <ignore regex="org.apache.log4j.*" /> <fileset dir="${bin.dir}"> <include name="**/*.class" /> <exclude name="**/T*Test.class" /> </fileset> </cobertura-instrument> <copy todir="${instrumented.dir}" preservelastmodified="true"> <fileset dir="${src.dir}"> <include name="**/*.xml" /> <include name="**/*.properties" /> </fileset> </copy> </target> |
[cobertura-junit单元测试]
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | <!-- ============================== --> <!-- cobertura-junit单元测试 --> <!-- ============================== --> <target name="cobertura-test" depends="cobertura-instrument" description="cobertura-test"> <delete dir="${junitxml.dir}" /> <mkdir dir="${junitxml.dir}" /> <junit fork="yes" printsummary="true" haltonfailure="no" haltonerror="no"> <classpath path="${instrumented.dir}" /> <classpath path="${bin.dir}" /> <classpath refid="classpath" /> <formatter type="xml" /> <batchtest todir="${junitxml.dir}"> <fileset dir="${src.dir}"> <include name="**/T*Test.java" /> </fileset> </batchtest> </junit> </target> |
[cobertura检查]
245 246 247 248 249 250 | <!-- ============================== --> <!-- cobertura检查 --> <!-- ============================== --> <target name="cobertura-check"> <cobertura-check branchrate="34" totallinerate="100" /> </target> |
[junit报告]
252 253 254 255 256 257 258 259 260 261 262 263 264 | <!-- ============================== --> <!-- junit报告 --> <!-- ============================== --> <target name="junit-report"> <delete dir="${junithtml.dir}" /> <mkdir dir="${junithtml.dir}" /> <junitreport todir="${junithtml.dir}"> <fileset dir="${junitxml.dir}"> <include name="TEST-*.xml" /> </fileset> <report format="frames" todir="${junithtml.dir}" /> </junitreport> </target> |
[cobertura报告]
266 267 268 269 270 271 272 273 274 275 276 | <!-- ============================== --> <!-- cobertura报告 --> <!-- ============================== --> <target name="cobertura-report"> <delete dir="${cobertura.dir}/xml" /> <mkdir dir="${cobertura.dir}/xml" /> <delete dir="${cobertura.dir}/html" /> <mkdir dir="${cobertura.dir}/html" /> <cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}/xml" format="xml"/> <cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}/html" /> </target> |
[junit+cobertura测试报告]
278 279 280 281 282 | <!-- ============================== --> <!-- junit+cobertura测试报告 --> <!-- ============================== --> <target name="report" depends="junit-report,cobertura-report"> </target> |
[运行主类]
284 285 286 287 288 289 290 291 | <!-- ============================== --> <!-- 运行主类 --> <!-- ============================== --> <target name="run"> <java classname="com.robertbao.base.quartz.ComQuartz" failonerror="true" fork="yes"> <classpath refid="classpath" /> </java> </target> |
[生成jar包]
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | <!-- ============================== --> <!-- 生成jar包 --> <!-- ============================== --> <target name="jar"> <delete> <fileset dir="${basedir}"> <include name="${app.name}.jar" /> </fileset> </delete> <jar destfile="${basedir}/${app.name}.jar" manifest="${basedir}/WebContent/META-INF/manifest.mf"> <fileset dir="${bin.dir}"> <include name="**/*" /> </fileset> <fileset dir="${basedir}/WebContent/WEB-INF"> <include name="**/*.xml" /> <exclude name="classes/hbm/*.xml" /> </fileset> <manifest> <attribute name="Main-Class" value="com.robertbao.base.main.Run" /> </manifest> </jar> </target> |
[全部运行]
316 317 318 319 | <!-- ============================== --> <!-- 全部运行 --> <!-- ============================== --> <target name="all" depends="clean,build,javadoc,warfile,junit-test" description="Clean,build,javadoc,warfile,junit-test" /> |
[清理ibatis自动生成代码]
321 322 323 324 325 326 327 328 | <!-- ============================== --> <!-- 清理ibatis自动生成代码 --> <!-- ============================== --> <target name="clean-ibatis" description="Clean ibatis dir"> <delete dir="${src.dir}/com/robertbao/${app.name}/po/dbauto" /> <delete dir="${src.dir}/com/robertbao/${app.name}/dao/dbauto" /> <delete dir="${src.dir}/com/robertbao/${app.name}/sqlmap/dbauto" /> </target> |
[zip压缩]
330 331 332 333 334 335 336 337 338 | <!-- ============================== --> <!-- zip压缩 --> <!-- ============================== --> <target name="zip"> <tstamp> <format property="date" pattern="yyyyMMdd" /> </tstamp> <jar jarfile="${basedir}/report${date}.zip" basedir="${junitreport.dir}" excludes="*.xml" /> </target> |
[发邮件]
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | <!-- ============================== --> <!-- 发邮件 --> <!-- ============================== --> <target name="mail"> <mail mailhost="smtp.gmail.com" mailport="465" user="" password="" subject="ant mail"> <from address="robertb9527@gmail.com" /> <to address="robertbao@robertbao.com" /> <message>The ${app.name} nightly build has completed</message> <attachments> <fileset dir="${basedir}"> <include name="*.zip" /> </fileset> </attachments> </mail> </target> |
[文件尾]
356 | </project> |

最新评论