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

查看:213
本文介绍了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"

从其他属性,以便解决性能似乎只能当属性做解决在蚂蚁文件本身的工作。

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?

推荐答案

蚂蚁不支持文件的扩展属性,请参阅的Property 任务。

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

我做快速测试这点,发现蚂蚁1.7.1并没有做使用命令行选项加载的文件在文件属性扩展。但是蚂蚁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.

这是蚂蚁的Bug 18732 。您应该能够通过更新Ant版本来解决。

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

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

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