2011-05-23 42 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项目中。