2011-05-23 84 views

回答

2

這可能是你在尋找什麼,

把這個作爲目標之一,你的父母的build.xml

<target name="executeChildBuild"> 

    <ant antfile="sub1/build.xml" target="build" /> 
    <ant antfile="sub2/build.xml" target="build" /> 

</target> 
+0

不是,我想要一個頂級build.xml遍歷所有子目錄,並在頂級build.xml中運行目標方法,並將子目錄名作爲參數。子目錄不會有單獨的build.xmls。 – eleshmistry 2011-05-23 14:38:15

+0

做你的意思是這樣,僞代碼: <迭代目錄名> <螞蟻antcall =「DoSomething的」參數=「$ {目錄名}」 /> – Adelave 2011-05-23 14:44:21

+0

沒錯,但在螞蟻 – eleshmistry 2011-05-23 14:48:24

1

如果你想做到這一點在ant build文件,你可以使用Ant Contrib's for task遍歷子目錄列表併爲每個子目錄執行ant任務。

<for param="subdir"> 
    <dirset dir="${build.dir}"> 
    <include name="./**"/> 
    </dirset> 
    <sequential> 
    <subant target="${target}"> 
     <property name="subdir.name" value="@{subdir}"/> 
    </subant> 
    </sequential> 
</for> 

我沒有測試這個代碼,因爲沒有安裝ant,但它接近你想要做的,我想。

+0

我已經取得了一些進展,我想使用Subant,但有一個問題: 我想設置一個屬性,每次運行它被設置爲目錄名稱,任何想法? – eleshmistry 2011-05-23 15:14:46

+1

已更新,代碼示例 – artplastika 2011-05-23 15:47:39

1

如果我正確地閱讀了這個問題,這可能是你正在尋找的東西。

因此,對於你的例子...

<target name="do-all"> 
    <antcall target="do-first"> 
     <param name="dir-name" value="first"/> 
     <param name="intented-target" value="init"/> 
    </antcall> 
    <antcall target="do-first"> 
     <param name="dir-name" value="second"/> 
     <param name="intented-target" value="build"/> 
    </antcall> 
    <antcall target="do-first"> 
     <param name="dir-name" value="third"/> 
     <param name="intented-target" value="compile"/> 
    </antcall> 
</target> 
<target name="do-first"> 
    <echo>Hello from ${dir-name} ${intented-target}</echo> 
    <ant antfile="${dir-name}/build.xml" target="${intented-target}"/> 
</target> 

當你從螞蟻調用這個,你會在命令行輸入:

ant do-all

和你的輸出應該看起來像此:

do-all:

do-first:

[echo] Hello from first init

do-first:

[echo] Hello from second build

do-first:

[echo] Hello from third compile

BUILD SUCCESSFUL Total time: 1 second

您當然需要確保您用作param的目錄名實際存在,否則構建將失敗。

您也可以始終通過將值添加到build.properties文件來提供您想要使用的變量。

1

看看subant任務。從這個頁面:

<project name="subant" default="subant1"> 
     <property name="build.dir" value="subant.build"/> 
     <target name="subant1"> 
      <subant target=""> 
       <property name="build.dir" value="subant1.build"/> 
       <property name="not.overloaded" value="not.overloaded"/> 
       <fileset dir="." includes="*/build.xml"/> 
      </subant> 
     </target> 
    </project> 

這個片段構建文件將運行在項目目錄,其中一個文件名爲build.xml可以發現每個子目錄螞蟻。屬性build.dir將具有值subant1。建立在subant調用的ant項目中。