English 中文(简体)
如何取得蚂蚁财产内的财产
原标题:How to acess property within a property in ant
  • 时间:2012-05-22 13:34:30
  •  标签:
  • ant

大家好,请看这个代码

in my properties file i have win-x86.pc-shared-location=E:Ant_Scripts

下面我正试图从我的建筑中调用 printInstallerName_building 。 而当 printInstallerName_building 在测试.xml 中, 在构建.xml 文件中, ${platform.id} 在调用目标中, 具有值=win- x86 , 在被调用的目标参数1 中, 也具有值=win-x86

    <target name="PrintInstallerName" >
    <echo>PlatForm.Id====>${platform.id}</echo>
    <ant antfile="test.xml" target="PrintInstallerName_build">
        <property name="param1" value="${platform.id}"/>
    </ant>


<target name="PrintInstallerName_build" >
       <echo>${param1.pc-shared-location}</echo><!--${param1.pc-shared-location}-->
        <echo>${param1}.pc-shared-location}</echo><!--win-x86.pc-shared-location-->
    <echo>${win-x86.pc-shared-location}</echo><!--E:\Ant_Scripts-->
</target>

您只能看到最后的语句给出正确的输出, 但是它是硬编码, 我想使用 param1, 而输出应该是 < code> E:\\ Ant_ Scripts i tried to $ and @ but no works, maybe I 正在某处做错事, 有人可以帮忙, i am am 。

最佳回答
<target name="PrintInstallerName_process" >
       <echo>${param1}</echo><!--win-x86-->

        <macrodef name="testing">
                <attribute name="v" default="NOT SET"/>
                <element name="some-tasks" optional="yes"/>
                    <sequential>
        <echo>Source Dir of ${param1}: ${@{v}}</echo><!-- Dir of Win-x86:E:Ant_Scripts-->
                                                    <some-tasks/>
                    </sequential>
            </macrodef>

            <testing v="${param1}.pc-shared-location">
                <some-tasks>

                </some-tasks>
            </testing>
    </target> 

对我来说,它的工作方式是正常的, 对我来说,它的工作方式是不错的, 反之, 你的小费带我到那里, 所以非常感谢你

问题回答

见《蚂蚁手册》>propertys 页面中的“Braress ”。

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:

the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace

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.

You can use <propertycopy> to make it happen.
Consider that you need to have the property value of ${propA${propB}}

使用 propertyopy 的蚂蚁标记如下:

<propertycopy property="myproperty" from="PropA.${PropB}"/>

<echo >${myproperty}</echo>

这将响应 ${propA${propB}{propB}{/code> 的值





相关问题
i want to continously run my java threads

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was ...

Subant targets instead of ant

I m having a problem with subant and have no ideas any more. Can anyone help? Using Ant to replace some strings for other (i.e Productname and Version for "Foo" and "1.2") I used ...

java ant buildfile for project with dependencies

I am new to ant, but am trying to create an ant script that builds my current proeject with another project as a dependency. I have the ant script building my current project, but am unsure how to add ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...