<?xml version="1.0" encoding="UTF-8"?>
<!-- mkdir javac jar clean -->
<project name="OurProject" default="archive" basedir="..\">
<target name="init" description="创建文件夹">
<mkdir dir="build\classes" description="用来放置类文件"/>
<mkdir dir="dist" description="用来放置打包文件"/>
</target>
<target name="compile" depends="init" description="编译源文件">
<javac srcdir="src" destdir="build/classes"></javac>
</target>
<target name="archive" depends="compile" description="打包">
<jar destfile="dist\project.jar" basedir="build\classes"></jar>
</target>
<target name="clean" description="清除类文件和打包文件">
<delete dir="build" description="如果该文件夹有打开的文件,删除失败"></delete>
<delete dir="dist"></delete>
</target>
</project> 
 第一次执行
D:\Workspaces\AntTest\src>ant -verbose
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Trying the default build file: build.xml
Buildfile: D:\Workspaces\AntTest\src\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jre6
Detected OS: Windows 7
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
Build sequence for target(s) `archive' is [init, compile, archive]
Complete build sequence is [init, compile, archive, clean, ]
init:
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/a
pache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[mkdir] Created dir: D:\Workspaces\AntTest\build\classes
[mkdir] Created dir: D:\Workspaces\AntTest\dist
compile:
[javac] D:\Workspaces\AntTest\src\build.xml:12: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Test2.java added as Test2.class doesn't exist.
[javac] D:\Workspaces\AntTest\src\ant skipped - don't know how to handle it
[javac] D:\Workspaces\AntTest\src\build.xml skipped - don't know how to handle it
[javac] D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.class skipped - don't know how to handle it
[javac] com\ankangqiao\HelloWorld.java added as com\ankangqiao\HelloWorld.class doesn't exist.
[javac] com\bjpowernode\test\Test.java added as com\bjpowernode\test\Test.class doesn't exist.
[javac] com\shengsiyuan\ant\custom\ApplicationException.java added as com\shengsiyuan\ant\custom\ApplicationException.class doesn't exist.
[javac] com\shengsiyuan\ant\custom\FileSorter.java added as com\shengsiyuan\ant\custom\FileSorter.class doesn't exist.
[javac] D:\Workspaces\AntTest\src\dest.txt skipped - don't know how to handle it
[javac] D:\Workspaces\AntTest\src\src.txt skipped - don't know how to handle it
[javac] Compiling 5 source files to D:\Workspaces\AntTest\build\classes
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'D:\Workspaces\AntTest\build\classes'
[javac] '-classpath'
[javac] 'D:\Workspaces\AntTest\build\classes;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-launcher.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-
antlr.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-bcel.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-bsf.jar;E:\JavaEE\Data\Ant\ap
ache-ant-1.8.2\lib\ant-apache-log4j.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-oro.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-
regexp.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-resolver.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-xalan2.jar;E:\JavaEE\Dat
a\Ant\apache-ant-1.8.2\lib\ant-commons-logging.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-commons-net.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib
\ant-jai.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-javamail.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-jdepend.jar;E:\JavaEE\Data\Ant\apach
e-ant-1.8.2\lib\ant-jmf.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-jsch.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-junit.jar;E:\JavaEE\Data\
Ant\apache-ant-1.8.2\lib\ant-junit4.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-netrexx.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-swing.jar;
E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-testutil.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant.jar;C:\Program Files\Java\jre6\lib\tools.jar'
[javac] '-sourcepath'
[javac] 'D:\Workspaces\AntTest\src'
[javac] '-g:none'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] Files to be compiled:
[javac] D:\Workspaces\AntTest\src\Test2.java
[javac] D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.java
[javac] D:\Workspaces\AntTest\src\com\bjpowernode\test\Test.java
[javac] D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\ApplicationException.java
[javac] D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\FileSorter.java
archive:
[jar] Building jar: D:\Workspaces\AntTest\dist\project.jar
[jar] adding directory META-INF/
[jar] adding entry META-INF/MANIFEST.MF
[jar] adding directory com/
[jar] adding directory com/ankangqiao/
[jar] adding directory com/bjpowernode/
[jar] adding directory com/bjpowernode/test/
[jar] adding directory com/shengsiyuan/
[jar] adding directory com/shengsiyuan/ant/
[jar] adding directory com/shengsiyuan/ant/custom/
[jar] adding entry Test2.class
[jar] adding entry com/ankangqiao/HelloWorld.class
[jar] adding entry com/bjpowernode/test/Test.class
[jar] adding entry com/shengsiyuan/ant/custom/ApplicationException.class
[jar] adding entry com/shengsiyuan/ant/custom/FileSorter.class
[jar] No Implementation-Title set.No Implementation-Version set.No Implementation-Vendor set.
[jar] Location: D:\Workspaces\AntTest\src\build.xml:16:
BUILD SUCCESSFUL
Total time: 1 second
 
如果执行第二遍,会有以下信息
D:\Workspaces\AntTest>ant -verbose -buildfile src/build.xml
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jre6
Detected OS: Windows 7
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
Build sequence for target(s) `archive' is [init, compile, archive]
Complete build sequence is [init, compile, archive, clean, ]
init:
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/a
pache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[mkdir] Skipping D:\Workspaces\AntTest\build\classes because it already exists.
[mkdir] Skipping D:\Workspaces\AntTest\dist because it already exists.
compile:
[javac] D:\Workspaces\AntTest\src\build.xml:11: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Test2.java omitted as D:\Workspaces\AntTest\build\classes\Test2.class is up to date.
[javac] D:\Workspaces\AntTest\src\build.xml skipped - don't know how to handle it
[javac] D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.class skipped - don't know how to handle it
[javac] com\ankangqiao\HelloWorld.java omitted as D:\Workspaces\AntTest\build\classes\com\ankangqiao\HelloWorld.class is up to date.
[javac] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\build\classes\com\bjpowernode\test\Test.class is up to date.
[javac] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\build\classes\com\shengsiyuan\ant\custom\Application
Exception.class is up to date.
[javac] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\build\classes\com\shengsiyuan\ant\custom\FileSorter.class is u
p to date.
[javac] D:\Workspaces\AntTest\src\dest.txt skipped - don't know how to handle it
[javac] D:\Workspaces\AntTest\src\src.txt skipped - don't know how to handle it
archive:
[jar] Test2.class omitted as D:\Workspaces\AntTest\dist\project.jar:Test2.class is up to date.
[jar] com\ankangqiao\HelloWorld.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/ankangqiao/HelloWorld.class is up to date.
[jar] com\bjpowernode\test\Test.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/test/Test.class is up to date.
[jar] com\shengsiyuan\ant\custom\ApplicationException.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/Applica
tionException.class is up to date.
[jar] com\shengsiyuan\ant\custom\FileSorter.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/FileSorter.class
is up to date.
[jar] com omitted as D:\Workspaces\AntTest\dist\project.jar:com/ is up to date.
[jar] com\ankangqiao omitted as D:\Workspaces\AntTest\dist\project.jar:com/ankangqiao/ is up to date.
[jar] com\bjpowernode omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/ is up to date.
[jar] com\bjpowernode\test omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/test/ is up to date.
[jar] com\shengsiyuan omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ is up to date.
[jar] com\shengsiyuan\ant omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/ is up to date.
[jar] com\shengsiyuan\ant\custom omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/ is up to date.
[jar] No Implementation-Title set.No Implementation-Version set.No Implementation-Vendor set.
[jar] Location: D:\Workspaces\AntTest\src\build.xml:15:
BUILD SUCCESSFUL
Total time: 0 seconds
 
 
如果修改了com\ankangqiao\HelloWorld.java
 会有以下信息
 
 D:\Workspaces\AntTest\src>ant -verbose
 Apache Ant(TM) version 1.8.2 compiled on December 20 2010
 Trying the default build file: build.xml
 Buildfile: D:\Workspaces\AntTest\src\build.xml
 Detected Java version: 1.6 in: C:\Program Files\Java\jre6
 Detected OS: Windows 7
 parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
 Project base dir set to: D:\Workspaces\AntTest
 Build sequence for target(s) `archive' is [init, compile, archive]
 Complete build sequence is [init, compile, archive, clean, ]
 
 init:
 parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/a
 pache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
     [mkdir] Skipping D:\Workspaces\AntTest\build\classes because it already exists.
     [mkdir] Skipping D:\Workspaces\AntTest\dist because it already exists.
 
 compile:
     [javac] D:\Workspaces\AntTest\src\build.xml:12: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for
 repeatable builds
     [javac] Test2.java omitted as D:\Workspaces\AntTest\build\classes\Test2.class is up to date.
     [javac] D:\Workspaces\AntTest\src\build.xml skipped - don't know how to handle it
     [javac] D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.class skipped - don't know how to handle it
     [javac] com\ankangqiao\HelloWorld.java added as com\ankangqiao\HelloWorld.class is outdated.
     [javac] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\build\classes\com\bjpowernode\test\Test.class is up to date.
     [javac] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\build\classes\com\shengsiyuan\ant\custom\Application
 Exception.class is up to date.
     [javac] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\build\classes\com\shengsiyuan\ant\custom\FileSorter.class is u
 p to date.
     [javac] D:\Workspaces\AntTest\src\dest.txt skipped - don't know how to handle it
     [javac] D:\Workspaces\AntTest\src\src.txt skipped - don't know how to handle it
     [javac] Compiling 1 source file to D:\Workspaces\AntTest\build\classes
     [javac] Using modern compiler
     [javac] Compilation arguments:
     [javac] '-d'
     [javac] 'D:\Workspaces\AntTest\build\classes'
     [javac] '-classpath'
     [javac] 'D:\Workspaces\AntTest\build\classes;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-launcher.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-
 antlr.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-bcel.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-bsf.jar;E:\JavaEE\Data\Ant\ap
 ache-ant-1.8.2\lib\ant-apache-log4j.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-oro.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-
 regexp.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-resolver.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-apache-xalan2.jar;E:\JavaEE\Dat
 a\Ant\apache-ant-1.8.2\lib\ant-commons-logging.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-commons-net.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib
 \ant-jai.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-javamail.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-jdepend.jar;E:\JavaEE\Data\Ant\apach
 e-ant-1.8.2\lib\ant-jmf.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-jsch.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-junit.jar;E:\JavaEE\Data\
 Ant\apache-ant-1.8.2\lib\ant-junit4.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-netrexx.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-swing.jar;
 E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant-testutil.jar;E:\JavaEE\Data\Ant\apache-ant-1.8.2\lib\ant.jar;C:\Program Files\Java\jre6\lib\tools.jar'
     [javac] '-sourcepath'
     [javac] 'D:\Workspaces\AntTest\src'
     [javac] '-g:none'
     [javac]
     [javac] The ' characters around the executable and arguments are
     [javac] not part of the command.
     [javac] File to be compiled:
     [javac]     D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.java
 
 archive:
       [jar] Test2.class omitted as D:\Workspaces\AntTest\dist\project.jar:Test2.class is up to date.
       [jar] com\ankangqiao\HelloWorld.class added as com/ankangqiao/HelloWorld.class is outdated.
       [jar] com\bjpowernode\test\Test.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/test/Test.class is up to date.
       [jar] com\shengsiyuan\ant\custom\ApplicationException.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/Applica
 tionException.class is up to date.
       [jar] com\shengsiyuan\ant\custom\FileSorter.class omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/FileSorter.class
 is up to date.
       [jar] com omitted as D:\Workspaces\AntTest\dist\project.jar:com/ is up to date.
       [jar] com\ankangqiao omitted as D:\Workspaces\AntTest\dist\project.jar:com/ankangqiao/ is up to date.
       [jar] com\bjpowernode omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/ is up to date.
       [jar] com\bjpowernode\test omitted as D:\Workspaces\AntTest\dist\project.jar:com/bjpowernode/test/ is up to date.
       [jar] com\shengsiyuan omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ is up to date.
       [jar] com\shengsiyuan\ant omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/ is up to date.
       [jar] com\shengsiyuan\ant\custom omitted as D:\Workspaces\AntTest\dist\project.jar:com/shengsiyuan/ant/custom/ is up to date.
       [jar] Building jar: D:\Workspaces\AntTest\dist\project.jar
       [jar] adding directory META-INF/
       [jar] adding entry META-INF/MANIFEST.MF
       [jar] adding directory com/
       [jar] adding directory com/ankangqiao/
       [jar] adding directory com/bjpowernode/
       [jar] adding directory com/bjpowernode/test/
       [jar] adding directory com/shengsiyuan/
       [jar] adding directory com/shengsiyuan/ant/
       [jar] adding directory com/shengsiyuan/ant/custom/
       [jar] adding entry Test2.class
       [jar] adding entry com/ankangqiao/HelloWorld.class
       [jar] adding entry com/bjpowernode/test/Test.class
       [jar] adding entry com/shengsiyuan/ant/custom/ApplicationException.class
       [jar] adding entry com/shengsiyuan/ant/custom/FileSorter.class
       [jar] No Implementation-Title set.No Implementation-Version set.No Implementation-Vendor set.
       [jar] Location: D:\Workspaces\AntTest\src\build.xml:16:
 
 BUILD SUCCESSFUL
 Total time: 1 second