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.

Apache Ant for DevOps: build.xml Fundamentals, Workflow, and Practical Commands

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

This page upgrades the original Apache Ant slides post into a hands-on reference for DevOps and build engineers. If you manage Java build pipelines, you will learn how Ant projects are organized, how targets run, which commands matter in daily use, and where Ant fits compared to Maven and Gradle.

What Apache Ant is and when to use it

Apache Ant is an XML-based build automation tool, widely used in Java ecosystems. It gives you explicit control over build steps through a build.xml file, where you define targets and their dependencies.

  • Use Ant when you need fine-grained, imperative control of build steps.
  • Use it for legacy Java projects that already rely on Ant targets/tasks.
  • Use it when pipeline steps map naturally to custom XML tasks and target chains.

Core concepts in an Ant build file

Ant builds are usually defined in a single build.xml file. The most important elements are:

  • project: root element with project name and default target.
  • target: named unit of work (for example clean, compile, jar).
  • depends: target dependency chain controlling execution order.
  • task: atomic action such as mkdir, javac, jar, delete.
  • property: reusable key/value setting for directories, filenames, and flags.

How target execution flows in Ant

When you invoke a target, Ant resolves dependencies first, then executes each target in order. If a required step fails (for example test or compile), downstream targets do not run.

flowchart TD
    A[Run ant jar] --> B[Load build.xml and properties]
    B --> C[Resolve target dependencies]
    C --> D[Run clean]
    D --> E[Run compile]
    E --> F{Compile successful}
    F -- yes --> G[Run jar]
    F -- no --> H[Stop build and report failure]

Minimal build.xml example

This example shows a small but realistic Ant setup with clean, compile, and jar targets.

<project name="demo-ant" default="jar" basedir=".">
    <property name="src.dir" value="src"/>
    <property name="build.dir" value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="dist.dir" value="dist"/>
    <property name="jar.file" value="${dist.dir}/demo-ant.jar"/>

    <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="clean,init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false"/>
    </target>

    <target name="jar" depends="compile">
        <jar destfile="${jar.file}" basedir="${classes.dir}"/>
    </target>
</project>Code language: HTML, XML (xml)

Useful Ant CLI commands

These commands are commonly used in local builds and CI jobs.

# Show available targets
ant -p

# Run a specific target
ant clean
ant compile
ant jar

# Run with an explicit build file
ant -f build.xml jar

# Override a property from CLI
ant -Dbuild.dir=out jarCode language: PHP (php)

Ant vs Maven vs Gradle

All three tools automate builds, but they differ in model and ergonomics.

ToolBuild styleBest forTrade-offs
Apache AntImperative XML targets/tasksCustom, step-by-step control and legacy Java buildsMore manual setup; fewer conventions out of the box
MavenConvention-driven lifecycle with POMStandardized Java project structures and dependency workflowsLess flexible for unusual build logic without extra plugins/config
GradleDeclarative + programmable build scriptsComplex multi-module builds and modern automation patternsHigher scripting complexity for teams that prefer strict conventions

Original Slideshare embed token from the source post

The original article was a short Slideshare embed. If your WordPress site still supports that shortcode, this is the original token from the post:

[slideshare id=1117746&doc=apacheant-090308134221-phpapp01]Code language: JSON / JSON with Comments (json)

Best practices and common pitfalls

  • Keep targets small and composable; use dependencies for flow.
  • Centralize paths and constants in property definitions.
  • Name targets clearly (clean, compile, test, package) to aid CI readability.
  • Avoid hidden side effects between targets; each target should be predictable.
  • Document required JDK/tools in repository docs so CI and local builds stay consistent.

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