一 Ant命令行
ant [options] [target [target2 [target3] ...]]
Options:
-help print this message
-projecthelp print project help information
-version print the version information and exit
-quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-emacs produce logging information without adornments
-logfile file use given file for log output
-logger classname the class that is to perform logging
-listener classname add an instance of class as a project listener
-buildfile file use specified buildfile
-find file search for buildfile towards the root of the filesystem and use the first one found
-Dproperty=value set property to value
常用的如下:
-version 要求Ant 显示其版本信息,然后退出。 -quiet 抑制并非由构建文件中的echo 任务所产生的大多数消息。
-verbose 显示构建过程中每个操作的详细消息。此选项与-debug 选项只能选其一。
-debug 显示Ant 和任务开发人员已经标志为调试消息的消息。此选项与-verbose 只能选其一。
-logfile filename 将日志输出重定向到指定文件。
-logger classname 指定一个类来处理Ant 的日志记录。所指定的类必须实现了org.apache. tools.ant.BuildLogger 接口。
-buildfile filename 指定Ant 需要处理的构建文件。默认的构建文件为build.xml。
-Dproperty=value 在命令行上定义一个特性名-值对。
-find filename 指定Ant 应当处理的构建文件。与-buildfile 选项不同,如果所指定文件在当前目录中未找到,-find 就要求Ant 在其父目录中再进行搜索。这种搜索会继续在其祖先目录中进行,直至达到文件系统的根为止,在此如果文件还未找到,则构建失败。
例如:
ant -buildfile test.xml -Dbuild=build/classes dist
使用当前目录下的test.xml运行Ant,执行一个叫做dist的target,并设定build属性的值为build/classes。
二 build.xml
如下实例为ant源码中用来构建ant的build.xml的简化
<project name="apache-ant" default="main" basedir=".">
<!-- Give user a chance to override without editing this file
(and without typing -D on each invocation) -->
<property file=".ant.properties"/>
<property file="${user.home}/.ant.properties"/>
<property environment="env"/>
<!--
===================================================================
Set the properties that control names and versions
===================================================================
-->
<property name="Name" value="Apache Ant"/>
<property name="name" value="ant"/>
<!-- this is the groupId of ant in the Maven repository -->
<property name="groupid" value="org/apache/ant"/>
<property name="project.version" value="1.8.2"/>
<!-- pom.version is used when doing a distribution and must match with what is checked in under src/etc/poms -->
<property name="pom.version" value="1.8.2-SNAPSHOT"/>
<property name="manifest-version" value="1.8.2"/>
<property name="bootstrap.jar" value="ant-bootstrap.jar"/>
<property name="ant.package" value="org/apache/tools/ant"/>
<property name="taskdefs.package" value="${ant.package}/taskdefs"/>
<property name="condition.package" value="${taskdefs.package}/condition"/>
<property name="optional.package" value="${taskdefs.package}/optional"/>
<property name="type.package" value="${ant.package}/types"/>
<property name="optional.type.package" value="${type.package}/optional"/>
<property name="apache.resolver.type.package" value="${ant.package}/types/resolver"/>
<property name="util.package" value="${ant.package}/util"/>
<property name="regexp.package" value="${util.package}/regexp"/>
<property name="optional.jars.prefix" value="ant"/>
<property name="optional.jars.whenmanifestonly" value="skip"/>
<!--
===================================================================
Set the properties related to the source tree
===================================================================
-->
<property name="src.dir" value="src"/>
<property name="java.dir" value="${src.dir}/main"/>
<property name="script.dir" value="${src.dir}/script"/>
<property name="lib.dir" value="lib"/>
<property name="docs.dir" value="docs"/>
<property name="etc.dir" value="${src.dir}/etc"/>
<property name="src.junit" value="${src.dir}/tests/junit"/>
<property name="src.antunit" value="${src.dir}/tests/antunit"/>
<property name="tests.etc.dir" value="${src.dir}/etc/testcases"/>
<property name="manifest" value="${src.dir}/etc/manifest"/>
<property name="resource.dir" value="${src.dir}/resources"/>
<!--
===================================================================
Set the properties for the build area
===================================================================
-->
<property name="build.dir" value="build"/>
<property name="bootstrap.dir" value="bootstrap"/>
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.lib" value="${build.dir}/lib"/>
<property name="build.javadocs" value="${build.dir}/javadocs"/>
<property name="build.tests" value="${build.dir}/testcases"/>
<property name="build.tests.javadocs" value="${build.dir}/javadocs.test/"/>
<property name="build.junit.xml" location="${build.tests}/xml"/>
<property name="antunit.xml" location="${build.dir}/antunit/xml"/>
<property name="antunit.reports" location="${build.dir}/antunit/reports"/>
<property name="antunit.loglevel" value="none"/>
<property name="build.junit.reports" location="${build.tests}/reports"/>
<property name="manifest.tmp" value="${build.dir}/optional.manifest"/>
<!-- the absolute path -->
<property name="build.tests.value" location="${build.tests}"/>
<!--
===================================================================
Set the properties that control various build options
===================================================================
-->
<property name="debug" value="true"/>
<property name="chmod.fail" value="true"/>
<property name="chmod.maxparallel" value="250"/>
<property name="deprecation" value="false"/>
<property name="optimize" value="true"/>
<property name="javac.target" value="1.4"/>
<property name="javac.source" value="1.4"/>
<property name="junit.filtertrace" value="off"/>
<property name="junit.summary" value="no"/>
<property name="test.haltonfailure" value="false"/>
<property name="junit.fork" value="true"/>
<property name="junit.forkmode" value="once"/>
<property name="expandproperty.files"
value="**/version.txt,**/defaultManifest.mf"/>
<property name="junit.collector.dir" value="${build.dir}/failingTests"/>
<property name="junit.collector.class" value="FailedTests"/>
<!--
===================================================================
Set the paths used in the build
===================================================================
-->
<path />
</dn:wix>
</target>
</project>