I Want to automate the ANT build process for deploying the applicaiton.

I want to write a ANT script which will recurringly should look for the build.xml files in the folder and run them, if the sub build is failed it should skip and continue to other script by writing log. Could any please post the idea which can help or a sample.

RootFolder
    |
    |-----Folder1
    |            |
    |            |--SubFolder1
    |            |            build.xml
    |            |--SubFolder2
    |            |            build.xml
    |-----Folder2
    |           build.xml
    |
    |-----Folder3
             build.xml
有帮助吗?

解决方案 2

I have solved my problem, thank you all for the reply, I used below technique to handle the situation.

<?xml version="1.0" ?> 
<project name="MasterBuildPrj" default="MasterBuild">
    <macrodef name="iterate">
        <attribute name="target"/>
        <sequential>
            <subant target="@{target}">
                <fileset dir="." 
                         includes="**/build.xml"
                         excludes="build.xml"/>
            </subant>
        </sequential>
    </macrodef>
    <target name="MasterBuild"  description="Build all sub projects">
        <iterate target="build"/>
    </target>

    <target name="clean"  description="Clean all sub projects">
        <iterate target="clean"/>
    </target>   
</project>

其他提示

I'd recommend using the subant task

<project name="Subant demo" default="deploy-everything">
    <target name="deploy-everything">
        <subant>
            <fileset dir="." includes="**/build.xml" excludes="build.xml"/>
            <target name="clean"/>
            <target name="deploy"/>
        </subant>
    </target>
</project>

This will find all "build.xml" files and call the "clean deploy" targets on each.

While it's neat to automatically pick up the sub folder builds, it rarely works in large projects unless the builds are independent of each other (build order is important).

The following example uses an explicit filelist, instead of a fileset which is unordered:

<project name="Subant demo" default="deploy-everything">
    <target name="deploy-everything">
        <subant>
            <filelist dir=".">
                <file name="Folder1/SubFolder1/build.xml"/>
                <file name="Folder1/SubFolder2/build.xml"/>
                ..
            </filelist>
            <target name="clean"/>
            <target name="build"/>
        </subant>
    </target>
</project>

Finally, the most advanced solution is to use a dependency manager like ivy to declare each module's dependencies in an "ivy.xml" file. Setup properly, this makes each sub module build more stand-alone. To solve the build "everything in only go problem" ivy provides a buildlist task that can automatically determine the correct build order:

<target name="deploy-everything">
    <ivy:buildlist reference="build-path">
        <fileset dir="." includes="**/build.xml" excludes="build.xml"/>
    </ivy:buildlist>

    <subant buildpathref="build-path">
        <target name="clean"/>
        <target name="build"/>
    </subant>
</target>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top