javaantmultiple-projectsbuild-tools

ANT Script to Compile/Build Multiple Projects


I want to Compile 2 projects in my workspace, in which projectB is dependent on projectA.

ProjectA

 |----src
 |----build.xml

ProjectB

 |----src
 |----build.xml

To Say I'm importing some packages from ProjectB. Now I have 2 Tasks

  1. How do I Compile ProjectB ?
  2. How do write ANT build.xml(master-build.xml) for both the Projects?strong text

Solution

  • In your Master-Build.xml, create targets to build project A and B and a target to build all:

    Example :

        <target name="build.projectB" depends="build.projectA">
             <ant antfile="${buildB}/deploy.xml" dir="." />
        </target>
    

    For the dependencies of your project B in your Master-Build.xml : - use the keyword depends="build.projectA" on the projectB target

    Example :

    <target name="A"/>
    <target name="B" depends="A"/>