Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Using Apache Ant to Build and Package J2EE Applications (WAR/EAR)

Apache Ant is a task-based build tool that can compile Java source code and package web and enterprise archives for J2EE applications (now commonly referred to as Jakarta EE). This guide is for engineers maintaining or modernizing Ant-based projects, and it covers a practical build flow, a reusable build.xml pattern, and CI-friendly command usage.

Originally published on 2010-03-21; fully revised and updated.

Slide deck reference from the original post

The original article was a short embed-only post. The Slideshare shortcode is preserved below for archival continuity.

{slideshare}[slideshare id=1117755&doc=usinganttobuildj2eeapplications-090308134153-phpapp02]{/slideshare}

How the Ant workflow maps to J2EE packaging

In a typical Ant-driven Java enterprise build, you clean old artifacts, compile Java classes, assemble a WAR for the web module, then optionally wrap that WAR into an EAR for deployment to an application server.

flowchart LR
    A[Developer updates source] --> B[Run ant clean]
    B --> C[Compile Java classes]
    C --> D[Copy web resources]
    D --> E[Build WAR file]
    E --> F[Assemble EAR file]
    F --> G[Publish artifact]
    G --> H[Deploy to application server]

Recommended project layout

A predictable directory structure keeps Ant targets easy to read and maintain.

  • src/main/java for Java source files
  • src/main/webapp for JSP/static files and WEB-INF/web.xml
  • src/main/application for EAR-level metadata such as META-INF/application.xml
  • lib for third-party JAR dependencies used at compile/package time
  • build for intermediate output (classes, temp files)
  • dist for final deployable artifacts (.war, .ear)

Example build.xml for compile, WAR, and EAR targets

This example shows a straightforward target chain: clean → compile → war → ear.

<project name="sample-j2ee-app" default="ear" basedir=".">
    <property name="src.dir" value="src/main/java"/>
    <property name="web.dir" value="src/main/webapp"/>
    <property name="build.dir" value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="dist.dir" value="dist"/>

    <path id="compile.classpath">
        <fileset dir="lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${dist.dir}"/>
    </target>

    <target name="init">
        <mkdir dir="${classes.dir}"/>
        <mkdir dir="${dist.dir}"/>
    </target>

    <target name="compile" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <target name="war" depends="compile">
        <war destfile="${dist.dir}/sample.war" webxml="${web.dir}/WEB-INF/web.xml">
            <fileset dir="${web.dir}"/>
            <classes dir="${classes.dir}"/>
            <lib dir="lib"/>
        </war>
    </target>

    <target name="ear" depends="war">
        <ear destfile="${dist.dir}/sample.ear" appxml="src/main/application/META-INF/application.xml">
            <fileset dir="${dist.dir}">
                <include name="sample.war"/>
            </fileset>
        </ear>
    </target>
</project>Code language: HTML, XML (xml)

Run common Ant commands

Use explicit targets in local development and CI so the build path is predictable.

ant clean
ant compile
ant war
ant ear
ant -Dbuild.number=20261012 ear

Ant vs Maven vs Gradle at a glance

If you are deciding whether to keep Ant or migrate, compare the build model and operational trade-offs.

ToolBuild definition styleDependency handlingTypical fit
AntExplicit XML targets and task orderManual management or add-on toolingLegacy builds needing fine-grained task control
MavenConvention-based lifecycle (POM)Built-in repository-driven modelTeams preferring standard Java conventions
GradleScripted DSL with tasks and pluginsBuilt-in repository-driven modelFlexible multi-module builds and custom automation

Common pitfalls and best practices

  • Keep artifact assembly deterministic: avoid hidden local dependencies outside lib or repository config.
  • Use clear target dependencies so ant ear always implies compile and WAR creation.
  • Parameterize environment-specific values with properties files instead of editing build.xml per environment.
  • Treat dist output as immutable deployment artifacts once built.
  • Document expected JDK level and app-server requirements alongside the build file.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Team Foundation Build 2010: Architecture, Build Definitions, and Migration from TFS 2008

Team Foundation Build 2010 introduced a controller/agent build architecture, richer build definitions, and gated check-in workflows for TFS teams. This revised guide turns the original topic list into a practical reference for setup, customization, and migration planning.

Read More

Team Foundation Server 2015: Practical Guide to Planning, Git, Builds, Testing, and Integrations

This guide turns an outline-style TFS 2015 post into a practical reference for real delivery workflows. Learn how to connect Agile planning, version control, CI builds, testing, and integrations in one on-prem pipeline.

Read More

Docker Training Agenda: A Hands-On Learning Path from Containers to Registries and Networking

This revised Docker training agenda turns the original outline into a practical, modern learning path for beginners and early-career DevOps engineers. It maps each module to hands-on outcomes, core commands, and common implementation decisions.

Read More

DevOps Training in Hyderabad: How to Evaluate Programs (with Legacy scmGalaxy Links)

This revised guide turns a legacy promotional post into a practical framework for choosing a DevOps training program in Hyderabad or online. It includes verification checklists, delivery model comparisons, and hands-on lab examples to assess course quality.

Read More

Puppet Training Agenda: A Practical Roadmap from Basics to Real-World Automation

This revised guide converts the original Puppet course outline into a clear learning path for DevOps and platform teams. It covers architecture, run cycle, hands-on manifests, ecosystem tools, and common implementation pitfalls.

Read More

Chef Training Roadmap for DevOps Engineers: Course Tracks, Lab Workflow, and Practical Commands

This guide turns a promotional Chef training post into a practical roadmap for engineers. Compare course levels, understand the learning workflow, and use hands-on commands you can run in a lab.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x