Search code examples
javajakarta-eeantear

Ant File, include another file


Let me describe the scenario first. I have a main build file called main_build.xml. This file calls 4 other build files defined for sub projects, copies the Jars generated by sub project builds and then creates a WAR and finally EAR.
I have my classpath dependencies defined in a XML file named my_clspath.xml.
Now I have two questions:
1. How do I include my_clspath.xml file within the main_build.xml?
2. After including the my_clspath.xml in main_build, how do I make the classpath available for all 4 sub builds which are called from this main_build?.

my_clspath.xml content:

<fileset dir="../myApp_Ear/build/">
    <include name="**/*.jar" />
</fileset>

<fileset dir="../myApp_Ear/lib/">
    <include name="**/*.jar" />
</fileset>


Solution

  • Try

    <project name="Your Project">
        <include file="my_clspath.xml" />
    
        <ant antfile="sub1.xml" inheritAll="true" inheritRefs="true" />
    </project>
    

    Also, you should set an id on the Filesets. Just having them in your Ant file does not do anything.

    <fileset dir="../myApp_Ear/build/" id="my.EAR.fileset">
        <include name="**/*.jar" />
    </fileset>
    

    Then, in sub1.xml, you can reference the filesets with <fileset refid="my.EAR.fileset" />

    Hope this helps.