ant的设置properties
特点
大小写敏感;
不可改变,先到先得,谁先设定,之后的都不能改变。
怎样设置
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 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

- <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:

- <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).

- <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.

- <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的设置properties的更多相关文章
- React+Ant Design设置左侧菜单导航路由的显示与隐藏(与权限无关)
最近在学习react时,用到了很流行的UI框架Ant Design,也了解了一下Ant Design Pro,发现它们都有导航组件,Ant Design框架的导航菜单在这里,Ant Design Pr ...
- eclipse设置properties文件的字体颜色
点击Window->preferences->搜素properties ============================ 其它设置字体颜色设置 =========== ...
- [Spring] - 动态设置properties
Spring的jar包用来做动态properties的getter/setter赋值方法: 1:需要的jar包: spring-beans-3.2.0.RC2.jar commons-logging- ...
- IntelliJ IDEA设置properties文件显示中文
配置这里: 注意:上面是Default Settings,还需要在Settings中设置成上面一样的.
- 在 Apache Ant中设置Proxy服务器
<target name="proxy"> <property name="proxy.host" value="https://m ...
- jmeter 使用ANT运行 设置自动停止时间
1.直接看图
- 在Eclipse中集成Ant配置
提要:本文将向你展示如何使用Eclipse设置为Ant所用的属性值和环境变量,并简要分析如何配置Ant编辑器以便从Eclipse内部操作Ant文件. 一. 修改Ant Classpath 在使用一个可 ...
- Ant :Property
Property Ant 内置的Property 系统属性 Ant附加的属性 自定义Property Ant :Property properties是由key-value组成的集合,就是Java中 ...
- ant 介绍 http://blog.csdn.net/sunjavaduke/archive/2007/03/08/1523819.aspx
转自: 本内容包含了Ant的历史简要介绍,Ant的功能以及Ant框架的介绍,并对下载安装使用Ant进行了示例介绍,同时通过一个Java程序讲解了Ant的基本使用方法. 1. Ant简介:这 ...
随机推荐
- Node.js 调试器
稳定性: 3 - 稳定 V8 提供了强大的调试工具,可以通过 TCP protocol 从外部访问.Node 内置这个调试工具客户端.要使用这个调试器,以debug参数启动 Node,出现提示: % ...
- MongoDB 排序
MongoDB sort()方法 在MongoDB中使用使用sort()方法对数据进行排序,sort()方法可以通过参数指定排序的字段,并使用 1 和 -1 来指定排序的方式,其中 1 为升序排列,而 ...
- J-Link固件烧录以及使用J-Flash向arm硬件板下载固件程序
这篇文章的最初版本是在15年写的https://blog.csdn.net/u010592722/article/details/45575663,后来又遇到了一些新问题,故更新在了这里. 一.始于安 ...
- Sharding-jdbc实现分库分表
首先在pom文件中引入需要的依赖 <dependency> <groupId>io.shardingjdbc</groupId> <artifactId> ...
- fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory
fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory ...
- android 自定义ViewGroup之浪漫求婚
*本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 1.最终效果 有木有发现还是很小清新的感觉 2.看整体效果这是一个scrollView,滑动时每个子view都有一个或多个动画效果 ...
- Scala: 简介和安装
http://blog.csdn.net/pipisorry/article/details/52902117 Note: lz只是稍微学学,能看懂就行,不深入.适合scala小白. Scala简介 ...
- 剑指Offer——常用SQL语句、存储过程和函数
剑指Offer--常用SQL语句.存储过程和函数 常用SQL语句 1.在MySQL数据库建立多对多的数据表关系 2.授权.取消授权 grant.revoke grant select, insert, ...
- 输入一个正数n,输出所有和为n连续正数序列。例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3个连续序列1-5、4-6和7-8。
输入一个正数n,输出所有和为n连续正数序列.例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3个连续序列1-5.4-6和7-8. #define N 15 void findS ...
- Android fragment(片段)构建灵活的UI
在以支持多种屏幕尺寸为目标设计应用时,您可以在不同的布局配置中重复使用您的fragment 从而根据可用的屏幕空间优化用户体验. 例如,在手机设备上,由于采用单窗格用户界面,因此可能更适合一次只显示一 ...