Ant 属性可以解析其他属性吗? [英] Can Ant properties resolve other properties?

查看:26
本文介绍了Ant 属性可以解析其他属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant 属性是否可以通过属性文件设置,从属性文件解析其他属性?

Can Ant properties set via properties file, resolve other properties from properties files?

例如,我可以这样做:

<property name="prop1" value="in_test_xml1" />
<property name="prop2" value="${prop1}" />

并且 prop2 变成in_test_xml1".那很好.

and prop2 becomes "in_test_xml1". That's good.

但在这种情况下,当使用输入属性文件时:

But in this case, when using an input properties file:

prop1=sample_prop
prop2=${prop1}

prop2 未设置为sample_prop"

prop2 is not set to "sample_prop"

所以从其他属性解析属性似乎只有在解析属性在 ant 文件本身中时才有效.

So resolving properties from other properties only seems to work when the property doing the resolving is in the ant file itself.

这是预期的还是我遗漏了什么?

Is this expected or am i missing something?

推荐答案

Ant 确实支持文件内属性扩展,请参阅 属性 任务.

Ant does support in-file property expansion, see the Property File section in the manual for the Property task.

以下示例显示属性得到解析:

The following example shows properties getting resolved:

  • 在单个属性文件中
  • 来自另一个属性文件中的一个属性文件
  • 在构建文件中

第一个属性文件:

$ cat props1.properties
prop1=world
prop2=hello ${prop1}

第二个属性文件:

$ cat props2.properties
prop3=goodbye ${prop1}

构建文件:

<project default="test">
  <property file="props1.properties"/>
  <property file="props2.properties"/>
  <property name="prop4" value="${prop3}, good luck"/>
  <target name="test">
    <echo message="prop1 = ${prop1}"/>
    <echo message="prop2 = ${prop2}"/>
    <echo message="prop3 = ${prop3}"/>
    <echo message="prop4 = ${prop4}"/>
  </target>
</project>

输出:

$ ant
Buildfile: build.xml

test:
     [echo] prop1 = world
     [echo] prop2 = hello world
     [echo] prop3 = goodbye world
     [echo] prop4 = goodbye world, good luck

BUILD SUCCESSFUL
Total time: 0 seconds

是否还有其他类型的财产解决方案不适合您?

Is there another kind of property resolution that is not working for you?

编辑

根据您的评论,我现在了解到您正在使用 -propertyfile 命令行选项来指定一个供 Ant 加载的属性文件(而不是像我那样在构建文件本身中指定该文件)以上).

Following your comment, I now understand that you are using the -propertyfile command line option to specify a property file for Ant to load (rather than specifying the file in the buildfile itself, as I did above).

我对此进行了快速测试,发现 Ant 1.7.1 没有对使用该命令行选项加载的文件进行文件内属性扩展.但是 Ant 1.8.2 可以.

I did quick test with this and find that Ant 1.7.1 did not do in-file property expansion on files loaded using that command line option. But Ant 1.8.2 does.

这是 Ant 错误 18732.您应该可以通过更新您的 Ant 版本来解决.

This is Ant Bug 18732. You should be able to resolve by updating your version of Ant.

这篇关于Ant 属性可以解析其他属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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