I have a build.xml which looks like this
<target name="foo">
<subant failonerror="false" target="p1">
<fileset dir="." includes="build.xml"/>
</subant>
<subant failonerror="false" target="p2">
<fileset dir="." includes="build.xml"/>
</subant>
<subant failonerror="false" target="p3">
<fileset dir="." includes="build.xml"/>
</subant>
</target>
When I do ant foo all the subants run simultaneosly. How do I make them run sequentially p1,p2,p3.
Is this part of your
build.xmlfile?Usually,
<subant/>, and<antcall/>tasks are a sign that the developer who created thebuild.xmldoes not understand Ant.Ant is not a programming language like Python, Java, C, etc. It is a dependency matrix language. That is, you give it targets to build, and instructions on what to build. For example, you might have a target named jar that builds your Jar file. This tasks consists mainly of the
<jar>command.What you do is say what your jar command depends upon. For example, it probably depends upon you compiling the code. Therefore, you say it depends upon your compile target. The compilation may require both to build the classpath from the ivy.xml file, and turning the WSDL files into Java code to compile.
However, before you can create your classpath from your
ivy.xmlfile, you must resolve it. And, before you turn your WSDL files into Java code, you want to fetch the latest versions of the WSDL from the project's website.I don't have to ask Ant to do any of this. All I ask it to do is to build the Jar, and Ant figured out what it needs to do in order to build the jar. I have given up my programmer's mindset of telling Ant each and every step it must take to do a particular task, and I have to trust Ant to figure out what it needs to do and in what order.
You say you want these tasks to run in a particular order. You are bringing the wrong mindset to Ant, and if this
footarget is an attempt to force the order, it's the wrong way.Ask yourself what you want to really do. No, you don't want to build
p1,p2,p3in that order.What you probably want to do is build whatever
p3builds. Maybe this is a jar or a war. Maybe this is a deployment of a war or ear to your website. That's what you really, really want to do. You don't care if you need to runp2orp1first, or whetherp1orp2has to get executed first. Give up the concept of telling Ant how to do every single step.Now, in order for your
build.xmlto execute the targetp3(deploying your war), it has to first execute the targetp2(building the war to deploy). That's a dependency onp3.Now, maybe for the
p2target to be executed, it first has to run thep1task (compile the Java code to create the classes your war needs). This is a dependency on thep2task.Here's a new simple
build.xmlthat shows this dependency tree. Note I don't use<antcall>,<ant>or<subant>tasks. I merely depend upon Ant to figure out what to do on its own.Now I'll run Ant specifying the target I really want to accomplish:
Notice that this did run
p1, p2, and p3in that order. However, nowhere in this file I actually stated that I wanted this done, and I really don't care. I just want to runp3. Ant figured out what targets it needs to run based upon the dependency tree.