特点

大小写敏感;

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

怎样设置

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

Xml代码
  1. <script
    language="javascript">
  2. propname =
    project.getProperty("anotherprop");
  3. project.setNewProperty("prop", propname);
  4. </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:

Xml代码
  1. <macrodef
    name="propertycopy">
  2. <attribute
    name="name"/>
  3. <attribute
    name="from"/>
  4. <sequential>
  5. <property
    name="@{name}"
    value="${@{from}}"/>
  6. </sequential>
  7. </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).

Xml代码
  1. <propertyhelper>
  2. <props:nested
    />
  3. </propertyhelper>
  4. <property
    name="foo"
    value="foo.value"
    />
  5. <property
    name="var"
    value="foo" />
  6. <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.

Xml代码
  1. <project
    xmlns:fl="antlib:it.haefelinger.flaka">
  2. <fl:install-property-handler/>
  3. <property
    name="foo"
    value="foo.value"/>
  4. <property
    name="var"
    value="foo" />
  5. <property
    name="buildtype"
    value="test"/>
  6. <property
    name="appserv_test"
    value="//testserver"/>
  7. <echo>
  8. #{${var}} = foo.value
  9. <!-- nested property -->
  10. #{appserv_${buildtype}}
  11. </echo>
  12. </project>

ant的设置properties的更多相关文章

  1. React+Ant Design设置左侧菜单导航路由的显示与隐藏(与权限无关)

    最近在学习react时,用到了很流行的UI框架Ant Design,也了解了一下Ant Design Pro,发现它们都有导航组件,Ant Design框架的导航菜单在这里,Ant Design Pr ...

  2. eclipse设置properties文件的字体颜色

    点击Window->preferences->搜素properties ============================ 其它设置字体颜色设置        =========== ...

  3. [Spring] - 动态设置properties

    Spring的jar包用来做动态properties的getter/setter赋值方法: 1:需要的jar包: spring-beans-3.2.0.RC2.jar commons-logging- ...

  4. IntelliJ IDEA设置properties文件显示中文

    配置这里: 注意:上面是Default Settings,还需要在Settings中设置成上面一样的.

  5. 在 Apache Ant中设置Proxy服务器

    <target name="proxy"> <property name="proxy.host" value="https://m ...

  6. jmeter 使用ANT运行 设置自动停止时间

    1.直接看图

  7. 在Eclipse中集成Ant配置

    提要:本文将向你展示如何使用Eclipse设置为Ant所用的属性值和环境变量,并简要分析如何配置Ant编辑器以便从Eclipse内部操作Ant文件. 一. 修改Ant Classpath 在使用一个可 ...

  8. Ant :Property

     Property Ant 内置的Property 系统属性 Ant附加的属性 自定义Property Ant :Property properties是由key-value组成的集合,就是Java中 ...

  9. ant 介绍 http://blog.csdn.net/sunjavaduke/archive/2007/03/08/1523819.aspx

    转自: 本内容包含了Ant的历史简要介绍,Ant的功能以及Ant框架的介绍,并对下载安装使用Ant进行了示例介绍,同时通过一个Java程序讲解了Ant的基本使用方法. 1.       Ant简介:这 ...

随机推荐

  1. Linux完全卸载Oracle的操作步骤

    卸载步骤如下:1.运行$ORACLE_HOME/bin/localconfig delete2.rm -rf $ORACLE_BASE/*3.rm -f /etc/oraInst.loc etc/or ...

  2. ABP文档笔记 - 事件BUS

    文档: ABP框架 - 领域事件(EventBus) EventBus & Domain Events ABP源码分析二十五:EventBus EventBus(事件总线) EventBus是 ...

  3. 网页底部广告悬浮弹窗(css)

    有的单页面需要添加广告等悬浮div. 部分代码: <div class="flex"> 内容.... </div> 主要css代码: .flex{posit ...

  4. 关于java的Synchronized,你可能需要知道这些(上)

    对于使用java同学,synchronized是再熟悉不过了.synchronized是实现线程同步的基本手段,然而底层实现还是通过锁机制来保证,对于被synchronized修饰的区域每次只有一个线 ...

  5. windows下 gvim8.0 编译器配置

    最近由于各种原因,IDE从source insight换成了vim,参考了诸多博客的文章,折腾了好久折腾了个大概的样子,现在总结一下经验: 主要参考: 改造vim变成source insight Wi ...

  6. MySQL NOW() 函数

    定义和用法 NOW() 返回当前的日期和时间. 语法 NOW() 实例 下面是 SELECT 语句: SELECT NOW(),CURDATE(),CURTIME() 结果如下所示: NOW() CU ...

  7. Dynamics CRM2016 Web Api之分页查询

    在dynamics crm web api还没出现前,我们是通过fetchxml来实现的,当然这种方式依旧可行,那既然web api来了我们就拥抱新的方式. web api中我们通过指定查询的条数来实 ...

  8. Dynamics 365 你所期待的子网格编辑终于来了

    Dynamics 365的online版本已经在11月1号发布了,on-premises版也在没几天后发布,今天略看了一眼 what's new 一眼就看到了 editable grids,这个不用我 ...

  9. Rails做rspec测试时出现bcrypt错误的解决

    在用rspec做测试的时候,出现了如下一句错误: You don't have bcrypt-ruby installed in your application. Please add it to ...

  10. iOS 应用打包命令一览

    文章转载自:http://www.jianshu.com/p/5d59966eaecc 文章排版部分根据自己的理解做了一些修改. 各种命令的简介 使用命令打包iOS 应用一般会用到 xcodebuli ...