3

こんにちは、このコードを見てください

私のプロパティファイルには win-x86.pc-shared-location=E:\Ant_Scripts があります

以下では、test.xml にあるPrintInstallerName_buildように、build.xmlから呼び出そうとしています。PrintInstallerName_buildbuild.xml ファイルで${platform.id} has value=win-x86は、呼び出し元のターゲットと呼び出されたターゲットの param1 にも value=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>

あなたが見ることができるように、最後のステートメントだけが正しい出力を与えますが、それはハードコードされてE:\\Ant_Scriptsいます。明日は国防総省です。

4

3 に答える 3

5

Ant マニュアルのプロパティページにある波括弧のネストを参照してください。

デフォルトの構成では、Ant はプロパティ展開で中括弧のバランスを取ろうとせず、プロパティ名を作成するときに最初の右中括弧までのテキストのみを消費します。つまり、 ${a${b}} のようなものを展開すると、2 つの部分に変換されます。

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

これは、名前がプロパティによって指定された簡単に展開できるプロパティを使用できないことを意味しますが、古いバージョンの Ant にはいくつかの回避策があります。Ant 1.8.0 と小道具 Antlib を使用すると、そのような機能が必要な場合に、そこで定義されている NestedPropertyExpander を使用するように Ant を構成できます。

于 2012-05-22T15:35:38.950 に答える
1
<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> 

これがその仕組みであり、私にとってはとにかくうまく機能し@sudocodeます。あなたのチップが私をそこに連れて行ってくれたので、どうもありがとうございました

于 2012-05-23T05:53:53.967 に答える