1 FileSet:
什么是FileSet,简单的将就是a group of files.可以进行Selector操作。就是说你可以选择将那些文件include进来或者exclude出去。
先看看其基本属性:
Attribute | Description | Required |
dir | the root of the directory tree of this FileSet. | Either dir or file must be specified |
file | shortcut for specifying a single-file fileset | |
defaultexcludes | indicates whether default excludes should be used or not (yes | no ); default excludes are used when omitted. | No |
includes | comma- or space-separated list of patterns of files that must be included; all files are included when omitted. | No |
includesfile | the name of a file; each line of this file is taken to be an include pattern. | No |
excludes | comma- or space-separated list of patterns of files that must be excluded; no files (except default excludes) are excluded when omitted. | No |
excludesfile | the name of a file; each line of this file is taken to be an exclude pattern. | No |
casesensitive | Must the include and exclude patterns be treated in a case sensitive way? Defaults to true. | No |
followsymlinks | Shall symbolic links be followed? Defaults to true. See the note below . | No |
erroronmissingdir | Specify what happens if the base directory does not exist. If true a build error will happen, if false, the fileset will be ignored/empty. Defaults to true. Since Apache Ant 1.7.1 (default is true for backward compatibility reasons.) | No |
例子:
在前面例子的基础上进行修改,作用是将old下面的两个文件old1.txt 和old2.txt拷贝到new下面去。
<target name="myTarget.check" depends="init">
<copy todir="${basedir}/new">
<fileset dir="${basedir}/old">
<include name="old1.txt" />
<include name="old2.txt" />
<exclude name="old8.txt" />
</fileset>
</copy>
</target>
输出结果:
myTarget.check:
[copy] Copying 2 files to D:/HelloAntWorld/new
myTarget:
all:
BUILD SUCCESSFUL
Total time: 1 second
在fileset中也可以结合其他的了解和selector使用,如:
<fileset dir="${server.src}" casesensitive="yes">
<filename name="**/*.java"/>
<not>
<filename name="**/*Test*"/>
</not>
</fileset>
2 讲下classFileset
A classfileset is a specialised type of fileset which, given a set of "root" classes, will include all of the class files upon which the
root classes depend.
This type requires thejakarta-BCEL
library.
除了遵循fileset里面的属性还支持:
Attribute | Description | Required |
rootclass | A single root class name | No |
When more than one root class is required, multiple nested <root>
elements may be used
Attribute | Description | Required |
classname | The fully qualified name of the root class | Yes |
举个简单的例子:
<classfileset id="reqdClasses" dir="${classes.dir}">
<root classname="org.apache.tools.ant.Project"/>
</classfileset>
这个意思就是说将org/apache/tools/ant/projet下所有的class包含起来形成一个fileset。
这个目前我还没用到过,看到再补充。。。。。。
3 Pattern:什么是pattern,你可以理解为模式匹配,在unix或者数据库语句中都曾有过的。比如*。
'*' matches zero or more characters,
'?' matches one character.
一般pattern都是在相对路径下开始搜索的。按照一个目录一个一个进行匹配。
比如/?abc/*/*.java
, 匹配/xabc/foobar/test.java
,
the first?abc
is matched withxabc
,
then*
is matched withfoobar
,
and finally*.java
is matched withtest.java
.
使用**可以在多个层次上搜索。
When**
is used as the name of a directory in the pattern, it matches zero or more directories.
例如:
/test/**
匹配/test/
下所有的文件和目录、
助于如果pattern以/
or/结尾
, then**
s appended.
例如mypackage/test/
将被解析为mypackage/test/**
.
FileSet上还有一些操作,先记下来由时间再看:
<checksum>
<copydir>
(deprecated)<delete>
<dependset>
<fixcrlf>
<javac>
<replace>
<rmic>
<style>
(aka<xslt>
)<tar>
<zip>
<ddcreator>
<ejbjar>
<ejbc>
<cab>
<native2ascii>
<netrexxc>
-
<renameextensions>
<depend>
<translate>
<image>
<jlink>
(deprecated)<jspc>
<wljspc>
FileLists:
FileLists are explicitly named lists of files. Whereas FileSets act as filters, returning only those files that exist in the file system and match specified patterns, FileLists are useful for specifying files that may or may not exist. Multiple files are specified as a list of files, relative to the specified directory, with no support for wildcard expansion (filenames with wildcards will be included in the list unchanged). FileLists can appear inside tasks that support this feature or as stand-alone types.
Attribute | Description | Required |
dir | The base directory of this FileList. | Yes |
files | The list of file names. This is a list of file name separated by whitespace, or by commas. | Yes, unless there is a nested file elem |
<filelist id="docfiles" dir="${doc.src}" files="foo.xml,bar.xml"/>
Note that these files may not (yet) actually exist.
6 PropertySet:
propertyref
Selects properties from the current project to be included in the set.
Attribute | Description | Required |
name | Select the property with the given name. | Exactly one of these. |
prefix | Select the properties whose name starts with the given string. | |
regex | Select the properties that match the given regular expression. Similar to regexp type mappers , this requires a supported regular expression library. | |
builtin | Selects a builtin set of properties. Valid values for this attribute are all for all Ant properties, system for the system properties and commandline for all properties specified on the command line when invoking Ant (plus a number of special internal Ant properties). |
<propertyset id="properties-starting-with-foo">
<propertyref prefix="foo"/>
</propertyset>
<propertyset id="properties-starting-with-bar">
<propertyref prefix="bar"/>
</propertyset>
<propertyset id="my-set">
<propertyset refid="properties-starting-with-foo"/>
<propertyset refid="properties-starting-with-bar"/>
</propertyset>
collects all properties whose name starts with either "foo" or "bar" in the set named "my-set".
7 ZipFileSet:
A <zipfileset>
is a special form of a <fileset >
which can behave in 2 different ways :
- When the src attribute is used - or a nested resource collection has been specified (since Apache Ant 1.7 ), the zipfileset is populated with zip entries found in the file src .
- When the dir attribute is used, the zipfileset is populated with filesystem files found under dir .
转载一篇资料:
Sun java的申明:
http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html#-jar