`
chen592969029
  • 浏览: 108558 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

ant property 总结

    博客分类:
  • Ant
阅读更多

特点

大小写敏感;

不可改变,先到先得,谁先设定,之后的都不能改变。

 

怎样设置

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

 

<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>
 
分享到:
评论

相关推荐

    ant1.9资源

    接下来开始向读者讲解本节的重点:Ant的关键元素project、target、property和task。 1. project元素 project元素是Ant构件文件的根元素,Ant构件文件至少应该包含一个project元素,否则会发生错误。在每个project...

    Maven权威指南 很精典的学习教程,比ANT更好用

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

    iuhyiuhkjh908u0980

    以下是我的ant脚本: &lt;project name="taxs_Admin" default="usage"&gt; &lt;property environment="env"&gt; by benlsoft 2008-09-04 回复 (0) 相关圈子讨论 springside配置ecside2.0怎么总 ... 报的错误脚本: form.action=...

    Activiti的安装详细过程

    &lt;property name="windows.browser" value="C:/Documents and Settings/dragon/Local Settings/Application Data/Google/Chrome/Application/chrome.exe" /&gt; 修改这个的目的是方便下面的 "ant demo.start" 结束后...

    Hibernate参考文档

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

    Hibernate 中文 html 帮助文档

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

    Hibernate中文详细学习文档

    1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...

    hibernate 框架详解

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

    hibernate 体系结构与配置 参考文档(html)

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

    hibernate3.04中文文档.chm

    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. 可选的配置...

    Hibernate教程

    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. 可选的配置属性 ...

    Hibernate+中文文档

    1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...

    HibernateAPI中文版.chm

    1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...

    hibernate3.2中文文档(chm格式)

    1.5. 总结 2. 体系结构(Architecture) 2.1. 概况(Overview) 2.2. 实例状态 2.3. JMX整合 2.4. 对JCA的支持 2.5. 上下文相关的(Contextual)Session 3. 配置 3.1. 可编程的配置方式 3.2. 获得...

    Hibernate3的帮助文档

    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. 双向关联 ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    Ant风格的pattern 4.7.2.2. classpath*: 前缀 4.7.2.3. 其他关于通配符的说明 4.7.3. FileSystemResource 提示 5. 校验,数据绑定,BeanWrapper,与属性编辑器 5.1. 简介 5.2. 使用Spring的Validator接口进行校验 ...

Global site tag (gtag.js) - Google Analytics