Question

I want to create Ant build script to build EAR from multiple WARs. I have 3 different web projects(3 different WARs). I need to know where I should keep the build.xml which builds EAR. Should I create a new EAR project in the parent folder of those 3 projects?

No correct solution

OTHER TIPS

Have you considered looking at Gradle. Gradle has support for multi-module projects and if you follow their conventions, the build scripts are fairly straight-forward. For this project, you would have three projects that generate a war (from each) and then a parent project that creates the ear and pulls in the war artifacts to create the ear file.

Worth a look, but I know you asked about Ant.

I have parent project with build.xml and subfolders containing individual modules

  1. build.xml
  2. ear-module/
  3. ejb-module/
  4. web-module/

The build.xml calls ant for each module and then assembles them together to result ear.

This is sample from single-ant having multiple modules. I prefer to have individual ant files in each module that is called from master folder. Dependencies can be tricky in ant. This is probably the reason why people favour maven/graddle over ant.

<target name="war" depends="ejb">
    <mkdir dir="${build.dir}/war" />
    <path id="web-classpath">
        <path refid="classpath" />
        <file file="${build.dir}/${ant.project.name}.jar" />
    </path>
    <javac srcdir="web-module/java" classpathref="web-classpath" destdir="${build.dir}/war" debug="true"
           source="${compiler.source.level}" target="${compiler.target.level}" encoding="${src.encoding}"/>
    <war destfile="${build.dir}/${ant.project.name}.war" webxml="web-module/war/WEB-INF/web.xml">
        <webinf dir="web-module/war/WEB-INF">
            <exclude name="web.xml"/>
            <exclude name="classes/**"/>
            <exclude name="lib/**"/>
        </webinf>
        <classes dir="${build.dir}/war" />
        <lib dir="web-module/war/WEB-INF/lib"/>
        <fileset dir="web-module/war">
            <exclude name="WEB-INF/*"/>
            <exclude name="META-INF/*"/>
        </fileset>
    </war>
</target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top