2013-05-20 91 views
1

我有一個build.xml應該接收動態參數到depends字段。 我在其他一些app.xml定義此參數,如:如何傳遞參數到ant任務的依賴字段

ops=op1, op2, op3,op4,op5,.... opn 

然後我導入此app.xmlbuild.xml,並希望使用該參數ops那裏。

<project name="Project" basedir="." default="help"> 
    <target name="test" depends="{$ops}" description="executea series of commands in ant"> 
     <echo message="batch operation job done. tasks = {$ops}"/> 
    </target> 
</project> 

如何將參數從一個ant文件傳遞給另一個?

+0

可能重複[在Ant中,我可以使用目標的「依賴」內的屬性?](http://stackoverflow.com/questions/1428200/in-ant-can-i-use-a-property- inside-a-targets-depends) –

+0

您需要將您的app.xml導入到build.xml文件中。請參閱此網址的語法:https://ant.apache.org/manual/Tasks/import.html – Jarvis

回答

2

depends參數不具有屬性。

Ant使用依賴矩陣來確定應該構建什麼以及按什麼順序。這個矩陣在之前計算構建文件本身的任何部分都被執行,所以當完成這些屬性時甚至不設置。

你想完成什麼?也許如果我們有更好的想法想要什麼,我們可以幫助你。 Ant不是像BASH或Python這樣的腳本語言。

0

如前所述,您不能將屬性放入取決於字段。但是,如果您要設置屬性,則可以在「If」字段中使用它。例如

<project name="appProject"> 

    <target name="test" depends="target1,target2,target3" description="execute series of commands"/> 

    <target name="target1" if="do.target1"> 
    <echo message="Target1 executed." /> 
    </target> 

    <target name="target2" if="do.target2"> 
    <echo message="Target2 executed." /> 
    </target> 

    <target name="target3" if="do.target3"> 
    <echo message="Target3 executed." /> 
    </target> 

</project> 

然後你在你的build.xml設置給定的目標標誌do.target1,do.target2或do.target3使它運行起來。基本上你想擁有什麼。在If字段屬性中只檢查值。另外,您不必爲屬性使用$ {}構造。