ant property总结
原文:http://chen592969029.iteye.com/blog/946056
特点
大小写敏感;
不可改变,先到先得,谁先设定,之后的都不能改变。
怎样设置
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.blogjava.net/wiflish/build.properties"/>, 导入http://www.blogjava.net/wiflish/build.properties 属性文件中的属性值。
7 、设置环境变量,比如: <property environment="env"/> ,设置系统的环境变量为前缀 env.
<property name="tomcat.home" value="${env.CATALINA_HOME}"/> 将系统的 tomcat 安装目录设置到 tomcat.home 属性中。
内置属性
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. |
System properties
java.version |
Java Runtime Environment version |
java.vendor |
Java Runtime Environment vendor |
java.vendor.url |
Java vendor URL |
java.home |
Java installation directory |
java.vm.specification.version |
Java Virtual Machine specification version |
java.vm.specification.vendor |
Java Virtual Machine specification vendor |
java.vm.specification.name |
Java Virtual Machine specification name |
java.vm.version |
Java Virtual Machine implementation version |
java.vm.vendor |
Java Virtual Machine implementation vendor |
java.vm.name |
Java Virtual Machine implementation name |
java.specification.version |
Java Runtime Environment specification version |
java.specification.vendor |
Java Runtime Environment specification vendor |
java.specification.name |
Java Runtime Environment specification name |
java.class.version |
Java class format version number |
java.class.path |
Java class path |
java.library.path |
List of paths to search when loading libraries |
java.io.tmpdir |
Default temp file path |
java.compiler |
Name of JIT compiler to use |
java.ext.dirs |
Path of extension directory or directories |
os.name |
Operating system name |
os.arch |
Operating system architecture |
os.version |
Operating system version |
file.separator |
File separator ("/" on UNIX) |
path.separator |
Path separator (":" on UNIX) |
line.separator |
Line separator ("\n" on UNIX) |
user.name |
User's account name |
user.home |
User's home directory |
user.dir |
User's current working directory |
用法
${key_name},如:${os.name},它将得到当前操作系统的名称。
需注意
1. 内置属性basedir
-- 不需要定义就可以直接使用,${basedir},得到当前工程的绝对路径
-- 当在<project>标签的basedir属性中指定basedir时,之后工程中出现的所有相对路径都是相对于这个basedir所指向的路径,且${basedir}的值也将变为<project>标签中的basedir属性所指定的值。
2. property的不变性在使用<available><ant><antcall>时会被打破
3. 可以在命令行通过-DpropertyName=propertyValue的方式指定property,注意,-D于propertyName之间没有空格,使用这种方式指定的属性最先被赋值,它是在执行build文件之前就已经赋值了的。
Q&A
How can I do something like <property name="prop" value="${${anotherprop}}"/>
(double expanding the property)?
Without any external help you can not.
With <script/>, which needs external libraries, you can do
![](http://chen592969029.iteye.com/images/icon_star.png)
- <script language="javascript">
- propname = project.getProperty("anotherprop");
- project.setNewProperty("prop", propname);
- </script>
With AntContrib (external task library) you can do <propertycopy name="prop" from="${anotherprop}"/>
.
With Ant 1.6 you can simulate the AntContribs <propertycopy> and avoid the need of an external library:
![](http://chen592969029.iteye.com/images/icon_star.png)
- <macrodef name="propertycopy">
- <attribute name="name"/>
- <attribute name="from"/>
- <sequential>
- <property name="@{name}" value="${@{from}}"/>
- </sequential>
- </macrodef>
With the 'props' antlib (external, but also from Ant) you could do the dereferencing with ${${anotherprop}
- not just in the property task - instead everywhere in your buildfile (after registering the required property helper).
![](http://chen592969029.iteye.com/images/icon_star.png)
- <propertyhelper>
- <props:nested />
- </propertyhelper>
- <property name="foo" value="foo.value" />
- <property name="var" value="foo" />
- <echo> ${${var}} = foo.value </echo>
With Flaka (external Ant Plugin) you could do the dereferencing with #{${anotherprop}}
- not just in flaka tasks, but all tasks after installing flaka's property handler.
![](http://chen592969029.iteye.com/images/icon_star.png)
- <project xmlns:fl="antlib:it.haefelinger.flaka">
- <fl:install-property-handler/>
- <property name="foo" value="foo.value"/>
- <property name="var" value="foo" />
- <property name="buildtype" value="test"/>
- <property name="appserv_test" value="//testserver"/>
- <echo>
- #{${var}} = foo.value
- <!-- nested property -->
- #{appserv_${buildtype}}
- </echo>
- </project>
ant property总结相关推荐
- Ant [BOOK]
第一章: Getting Started l Ant 默认的构建文件为 build.xml l Ant 构建文件中的根 XML 元素为 project , proj ...
- Gradle学习之基础篇
一.gradle基础概念 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.Gradle抛弃了基于各种繁琐的XML,使用一种基于Groovy的特定领域语言( ...
- Android --- Gradle是什么?
威哥学习Java写了大半年的Android,今天打开项目,一直疑惑着项目里面这么多后缀.gradle,到底是干嘛的呢?汗颜啊!!! 所有网上总结了下,和初学Android的同学一起分享下. 首先我们的 ...
- Hadoop1.1.2 Eclipse 插件编译
可以直接下载我编译好的插件 hadoop-eclipse-plugin-1.1.2 http://download.csdn.net/detail/wind520/5784389 1:方法一: cop ...
- 让开发自动化: 利用 Ivy 管理依赖项
http://www.ibm.com/developerworks/cn/java/j-ap05068/index.html 实际上,所有软件开发项目都必须依靠来自其他项目的源代码.例如,许多项目可能 ...
- 一个实际的sonar代码检查的配置文件
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- 文件用户Apache shiro学习笔记+ spring整合shiro (一)
改章节朋友在青岛游玩的时候突然想到的...这两天就有想写几篇关于文件用户的博客,所以回家到之后就奋笔疾书的写出来发表了 Apache Shiro官网:http://shiro.apache.org/ ...
- Window平台的eclipse连接linux的hadoop集群
前提条件:之前已经在VM上虚拟了三台linux,并且安装了hadoop集群 feixu-master, feixu-slave1, feixu-slave2, feixu-slave3 需求: 为了开 ...
- Android Gradle是什么?
威哥学习Java写了大半年的Android,今天打开项目,一直疑惑着项目里面这么多后缀.gradle,到底是干嘛的呢?汗颜啊!!! 所有网上总结了下,和初学Android的同学一起分享下. 首先我们的 ...
最新文章
- 前沿 | DeepMind 最新研究——神经算术逻辑单元,有必要看一下!
- pandas创建时间序列仿真数据并过滤(filter)时间数据:头尾数据、某年的数据、某年某月的数据、某年某月某日的数据、某个时间范围内的数据、truncate函数查看特定时间之前护着之后的数据
- 有向图的强连通分量——Tarjan
- DNS子域委派配置案例[转载]
- 不同品牌发电机组间的并机知识
- BP: Useful report to list assigned employees
- vue学习—Convert HTML string to AST,如何将html字符串转换为ast数组结构
- Java笔记-Spring Boot中Spring WS WS-Addressing中@Action实例
- java会跳出problem_docs/java/concurrent/ConcurrencyProblem.md · wt1814/wt-note - Gitee.com
- 蒙特利尔问题(三门问题)的解释
- 解密常见的社会工程学攻击
- 【EmmyLua插件】Rider无法跳转lua文件解决
- Spring核心之一:Spring的配置文件是干什么的
- android点击特效,android 点击特效动画
- 米勒-拉宾质数判断证明
- Vue - $route matched 属性实现面包屑导航
- 空间数据分析以及QGIS数据加载
- vscode 插件-常用插件
- J2EE总体的学习计划(百搜技术)
- 基于RTMP协议的Flash流媒体网页直播播放器