详见:http://ant.apache.org/manual/index.html
1.特点
大小写敏感;
不可改变,先到先得,谁先设定,之后的都不能改变。
如下的build.xml
<project name="MbopManageWeb" default="release" basedir="..">
<property name="releasedir" value="D:\anttest\mbop" />
<property name="releasedir" value="D:\anttest\manage" />
<echo>打包后发布路径:${releasedir}</echo>
<target name="release">
<delete dir="${releasedir}" />
<mkdir dir="${releasedir}" />
</target>
</project>
执行后控制台的打印信息如下所示:
Buildfile: D:\myworkspace\MbopManageWeb\build\build_test.xml
[echo] 打包后发布路径:D:\anttest\mbop
release:
[delete] Deleting directory D:\anttest\mbop
[mkdir] Created dir: D:\anttest\mbop
BUILD SUCCESSFUL
Total time: 172 milliseconds
“D:\anttest\mbop”,说明它的值一旦设定后,就无法再修改了。
2、property类似于变量,可以提供给build.xml中的其他元素使用
<property>元素可以跟很多种属性,各属性如下所示:
Attribute |
Description |
Required |
name |
the name of the property to set. |
No |
value |
the value of the property. |
One of these or nested text, when using the name attribute |
location |
Sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded. |
refid |
Reference to an object defined elsewhere. Only yields reasonable results for references toPATH like structures or properties. |
resource |
the name of the classpath resource containing properties settings in properties file format. |
One of these, whennot using the name attribute |
file |
the location of the properties file to load. |
url |
a url containing properties-format settings. |
environment |
the prefix to use when retrieving environment variables. Thus if you specify environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM". Note that if you supply a property name with a final "." it will not be doubled; i.e. environment="myenv." will still allow access of environment variables through "myenv.PATH" and "myenv.TERM". This functionality is currently only implemented on select platforms. Feel free to send patches to increase the number of platforms on which this functionality is supported ;). Note also that properties are case-sensitive, even if the environment variables on your operating system are not; e.g. Windows 2000's system path variable is set to an Ant property named "env.Path" rather than "env.PATH". |
classpath |
the classpath to use when looking up a resource. |
No |
classpathref |
the classpath to use when looking up a resource, given as reference to a <path> defined elsewhere.. |
No |
prefix |
Prefix to apply to properties loaded using file , resource , or url . A "." is appended to the prefix if not specified. |
No |
prefixValues |
Whether to apply the prefix when expanding the right hand side of properties loaded usingfile , resource , or url . Since Ant 1.8.2
|
No (default=false) |
relative |
If set to true the relative path to basedir is set. Since Ant 1.8.0
|
No (default=false) |
basedir |
The basedir to calculate the relative path from. Since Ant 1.8.0
|
No (default=${basedir}) |
3. 7种设置方式
1)、设置name和value属性值,比如:<property name="srcdir" value="${basedir}/src"/>
2)、设置name和refid属性值,比如:<property name="srcpath" refid="dao.compile.classpath"/>,其中dao.compile.classpath在别的地方定义。
3)、设置name和location属性值,比如:<property name="srcdir" location="src"/>,即将srcdir的值设置为:当前项目根目录的/src目录。
4)、设置file属性值,比如:<property file="build.properties"/>, 导入build.properties属性文件中的属性值
5)、设置resource属性值,比如:<propety resource="build.properties"/>,导入build.properties属性文件中的属性值
6)、设置url属性值,比如:<property url="http://www.mysite.com/bla/props/foo.properties"/>,导入http://www.mysite.com/bla/props/foo.properties属性文件中的属性值。
7)、设置环境变量,比如:<property environment="env"/>,设置系统的环境变量为前缀env.
<property name="tomcat.home" value="${env.CATALINA_HOME}"/> 将系统的tomcat安装目录设置到tomcat.home属性中。
4.内置属性
Ant’s built-in properties:
basedir
|
The absolute path of the project’s basedir.
|
ant.file
|
The absolute path of the buildfile.
|
ant.version
|
The version of Ant.
|
ant.project.name
|
The name of the project that is currently executing.
|
ant.project.default-target
|
The name of the currently executing project’s default target.
|
ant.project.invoked-targets
|
A comma separated list of the targets that have been specified on the command line when invoking the current.
|
ant.java.version
|
The JVM version Ant detected.
|
ant.core.lib
|
The absolute path of the ant.jar file.
|
内置属性basedir
-- 不需要定义就可以直接使用,${basedir},得到当前工程的绝对路径
-- 当在<project>标签的basedir属性中指定basedir时,之后工程中出现的所有相对路径都是相对于这个basedir所指向的路径,且${basedir}的值也将变为<project>标签中的basedir属性所指定的值。
5. 只有在声明了property之后,才能引用它,否则的话就会视为普通的字符串,比如 、
<mkdir dir="${build.classes.dir}" />
如果这个时候还没有声明build.classes.dir,那么就会视为${build.classes.dir}
分享到:
相关推荐
接下来开始向读者讲解本节的重点:Ant的关键元素project、target、property和task。 1. project元素 project元素是Ant构件文件的根元素,Ant构件文件至少应该包含一个project元素,否则会发生错误。在每个project...
Property References in Assembly Descriptors 12.4.2. Required Assembly Information 12.5. Controlling the Contents of an Assembly 12.5.1. Files Section 12.5.2. FileSets Section 12.5.3. Default ...
以下是我的ant脚本: <project name="taxs_Admin" default="usage"> <property environment="env"> by benlsoft 2008-09-04 回复 (0) 相关圈子讨论 springside配置ecside2.0怎么总 ... 报的错误脚本: form.action=...
<property name="windows.browser" value="C:/Documents and Settings/dragon/Local Settings/Application Data/Google/Chrome/Application/chrome.exe" /> 修改这个的目的是方便下面的 "ant demo.start" 结束后...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得SessionFactory 3.3...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得SessionFactory 3.3...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...
用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联工作 2.3.4. 值类型的集合 2.3.5. 双向关联 2.3.6....
用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 1.3.5. 双向关联 1.3.6. 使...
2.4. 总结 3. 体系结构(Architecture) 3.1. 概况(Overview) 3.2. 实例状态 3.3. JMX整合 3.4. 对JCA的支持 4. 配置 4.1. 可编程的配置方式 4.2. 获得SessionFactory 4.3. JDBC连接 4.4. 可选的配置...
2.4. 总结 3. 体系结构(Architecture) 3.1. 概况(Overview) 3.2. 实例状态 3.3. JMX整合 3.4. 对JCA的支持 4. 配置 4.1. 可编程的配置方式 4.2. 获得SessionFactory 4.3. JDBC连接 4.4. 可选的配置属性 ...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...
1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...
2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联工作 2.3.4. 值类型的集合 2.3.5. 双向关联 ...
Ant风格的pattern 4.7.2.2. classpath*: 前缀 4.7.2.3. 其他关于通配符的说明 4.7.3. FileSystemResource 提示 5. 校验,数据绑定,BeanWrapper,与属性编辑器 5.1. 简介 5.2. 使用Spring的Validator接口进行校验 ...