是否可以将属性的值指定为 ant 中的属性? [英] Is it possible to specify value of property as property in ant?

查看:24
本文介绍了是否可以将属性的值指定为 ant 中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性文件,它是在执行过程中由我的 ant 脚本本身生成的.我想从这个生成的属性文件中访问属性的值.

I have a property file which is generated by my ant script itself during execution. And I want to access the value of properties from this generated property file.

例如,

生成的属性文件:

first.prop=abcd
second.prop=pqrs

在脚本中,我试图像这样访问它,

and in script, I am trying to access it like this,

我有一个来自其他属性的属性名称(我想访问它并且在生成的属性文件中).该属性是 name.prop.所以,

I am having a property name (that I want to access and is in generated property file) from some other property. That property is name.prop. so,

<echo message="${name.prop}"/>
<echo message="${${name.prop}}"/>

给予

first.prop
${${name.prop}}

分别作为输出.有什么办法可以解决这个问题?

as output respectively. What can be the solution over this?

推荐答案

本文来自 doc:

大括号的嵌套

在默认配置中,Ant 不会尝试平衡大括号属性扩展,它只会消耗文本到第一个创建属性名称时的右大括号.IE.扩张时像 ${a${b}} 这样的东西会被翻译成两部分:

In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:

  • 属性 a${b 的扩展 - 可能没什么用处.
  • 第二个右大括号产生的文字 }

这意味着您不能轻松地使用名称为由属性给出,但对于旧版本有一些解决方法蚂蚁.使用 Ant 1.8.0 和 props Antlib,您可以配置 Ant如果您需要这样的,请使用在那里定义的 NestedPropertyExpander功能.

This means you can't use easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature.

所以它不容易获得.解决方法(使用

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆