<?xml version="1.0" encoding="UTF-8"?>
<!--copy fileset **\*.java-->
<project name="fileset" default="copyFile" basedir="..\">
<description>拷贝文件到指定的文件夹</description>
<fileset dir="src" includes="**\*.java" id="source.fileset" description="src文件夹及其子文件夹所有以java结尾的文件"></fileset>
<target name="copyFile" description="拷贝文件">
<copy todir="backup" description="若无此文件夹,自动创建">
<fileset refid="source.fileset"></fileset>
</copy>
</target>
</project>
<!--
第一次执行ant
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
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
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/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
[copy] Test2.java added as Test2.java doesn't exist.
[copy] com\ankangqiao\HelloWorld.java added as com\ankangqiao\HelloWorld.java doesn't exist.
[copy] com\bjpowernode\test\Test.java added as com\bjpowernode\test\Test.java doesn't exist.
[copy] com\shengsiyuan\ant\custom\ApplicationException.java added as com\shengsiyuan\ant\custom\ApplicationException.java doesn't exist.
[copy] com\shengsiyuan\ant\custom\FileSorter.java added as com\shengsiyuan\ant\custom\FileSorter.java doesn't exist.
[copy] No sources found.
[copy] Copying 5 files to D:\Workspaces\AntTest\backup
[copy] Copying D:\Workspaces\AntTest\src\Test2.java to D:\Workspaces\AntTest\backup\Test2.java
[copy] Copying D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.java to D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java
[copy] Copying D:\Workspaces\AntTest\src\com\bjpowernode\test\Test.java to D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java
[copy] Copying D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\ApplicationException.java to D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java
[copy] Copying D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\FileSorter.java to D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java
BUILD SUCCESSFUL
Total time: 731 milliseconds
在没有任何改动的情况下,第二次执行ant
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
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
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/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
[copy] Test2.java omitted as D:\Workspaces\AntTest\backup\Test2.java is up to date.
[copy] com\ankangqiao\HelloWorld.java omitted as D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java is up to date.
[copy] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java is up to date.
[copy] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java is up to date.
[copy] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java is up to date.
[copy] No sources found.
BUILD SUCCESSFUL
Total time: 395 milliseconds
因为文件夹中的文件跟要拷贝的源文件的内容和名字完全一致,所以任务不再执行
第三次执行ant(对Test2.java做了修改)
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
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
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/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
[copy] Test2.java added as Test2.java is outdated.
[copy] com\ankangqiao\HelloWorld.java omitted as D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java is up to date.
[copy] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java is up to date.
[copy] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java is up to date.
[copy] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java is up to date.
[copy] No sources found.
[copy] Copying 1 file to D:\Workspaces\AntTest\backup
[copy] Copying D:\Workspaces\AntTest\src\Test2.java to D:\Workspaces\AntTest\backup\Test2.java
BUILD SUCCESSFUL
Total time: 411 milliseconds
虽然Test2.java在目标文件夹中已经存在,但是源文件已经做了修改,ant认为目标文件夹中得文件已经过时,需要覆盖掉,所以拷贝覆盖
-->