以前一直都用eclipse进行项目构建、编译、测试、部署,所有的一切都依赖于IDE。如果离开IDE(比如需要在某台linux机器上进行开发,没有GUI界面),则想调试将比较难(因为本地有时无法模拟生产机器的环境),于是最近利用空余时间看了下Ant构建方面的资料,整出如下build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
2011-6-23 下午05:23:55
chenza
====================================================================== -->
<project name="monkey-build" default="package" basedir=".">
<property name="src.dir" location="src"/>
<property name="src.main.dir" location="${src.dir}/main"/>
<property name="src.test.dir" location="${src.dir}/test"/>
<property name="build.dir" location="build"/>
<property name="build.main.dir" location="${build.dir}/main"/>
<property name="build.test.dir" location="${build.dir}/test"/>
<property name="lib.dir" location="lib"/>
<property name="dist.dir" location="dist"/>
<property name="bin.dir" location="bin"/>
<property name="test.data.dir" location="${build.dir}/data"/>
<property name="test.report.dir" location="${build.dir}/report"/>
<property name="test.suite" value="com.monkey.util.HelloMonkeyTest"/>
<property name="svn.remote.url" value="http://mushroom-monkey.googlecode.com/svn/mushroom/"/>
<path id="path.svnant">
<pathelement location="${lib.dir}/svnjavahl.jar"/>
<pathelement location="${lib.dir}/svnant.jar"/>
<pathelement location="${lib.dir}/svnClientAdapter.jar"/>
<pathelement location="${lib.dir}/ganymed.jar"/>
<pathelement location="${lib.dir}/jna.jar"/>
<pathelement location="${lib.dir}/svnkit.jar"/>
<!--
-->
</path>
<typedef
resource="org/tigris/subversion/svnant/svnantlib.xml"
classpathref="path.svnant"
/>
<target name="init">
<tstamp/>
<mkdir dir="${src.main.dir}"/>
<mkdir dir="${src.test.dir}"/>
<mkdir dir="${build.main.dir}"/>
<mkdir dir="${build.test.dir}"/>
<mkdir dir="${test.data.dir}"/>
<mkdir dir="${test.report.dir}"/>
<mkdir dir="${lib.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="logs"/>
<mkdir dir="conf/spring"/>
</target>
<path id="project.classpath">
<fileset dir="${lib.dir}" id="lib_dir">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="build.main.path">
<pathelement location="${build.main.dir}"/>
<pathelement location="${build.test.dir}"/>
</path>
<target name="compile.main" depends="init">
<javac encoding="UTF-8" srcdir="${src.main.dir}" destdir="${build.main.dir}" debug="true"
includeantruntime="true" includejavaruntime="true">
<classpath refid="project.classpath"/>
</javac>
</target>
<target name="compile.test" depends="compile.main">
<javac encoding="UTF-8" srcdir="${src.test.dir}" destdir="${build.test.dir}" debug="true"
includeantruntime="true" includejavaruntime="true">
<classpath refid="project.classpath"/>
<classpath refid="build.main.path"/>
</javac>
</target>
<target name="package" depends="compile.main">
<delete file="${dist.dir}/monkey-sdk.jar"></delete>
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="project.classpath" />
<globmapper from="${lib.dir}*.jar" to="lib*.jar" />
</pathconvert>
<jar destfile="${dist.dir}/monkey-sdk.jar"
basedir="${build.main.dir}"
includes="com/**">
<manifest>
<attribute name="Main-Class" value="com.monkey.util.HelloMonkey"/>
<attribute name="Class-Path" value="${mf.classpath}"/>
</manifest>
</jar>
</target>
<target name="package.src">
<delete file="${dist.dir}/monkey-sdk-src.jar"></delete>
<jar destfile="${dist.dir}/monkey-sdk-src.jar"
basedir="${src.dir}"/>
</target>
<target name="ipconfig">
<exec executable="ipconfig">
</exec>
</target>
<target name="test-basic" depends="compile.test"> <!-- printsummary="withOutAndErr" -->
<junit haltonfailure="true" printsummary="false"><!-- build process halt when test fail -->
<classpath refid="project.classpath"/>
<classpath refid="build.main.path"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<!--
<test name="${test.suite}"/>
-->
<batchtest todir="${test.data.dir}">
<fileset dir="${build.test.dir}"
includes="**/*Test.class" />
</batchtest>
</junit>
<junitreport todir="${test.data.dir}">
<fileset dir="${test.data.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.report.dir}"/>
</junitreport>
</target>
<target name="test-report" depends="compile.test">
<junit printsummary="false" failureproperty="test.fail" errorproperty="test.fail">
<classpath refid="project.classpath"/>
<classpath refid="build.main.path"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.data.dir}">
<fileset dir="${build.test.dir}"
includes="**/*Test.class" />
</batchtest>
</junit>
<junitreport todir="${test.data.dir}">
<fileset dir="${test.data.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.report.dir}"/>
</junitreport>
<fail if="test.fail">
Tests failed. Check ${test.report.dir}
</fail>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="update">
<svn javahl="true" username="cza55007@gmail.com" password="*********">
<checkout url="${svn.remote.url}" revision="HEAD" destpath="${build.dir}" />
</svn>
</target>
</project>
且当做笔记,同时也供有此困惑的朋友们参考,如有问题,请批评指正。