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 Fundamentals: build.xml, Targets, Commands, and CI/CD Usage

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

Apache Ant is a build automation tool used heavily in Java ecosystems to turn source code into repeatable artifacts. This guide helps DevOps and build engineers understand how Ant works, how to run it reliably in CI/CD, and when Ant is the right choice compared with Maven or Gradle.

The original post was a SlideShare-only teaser. This revision provides a complete written reference and keeps the original permalink for context: Power Point PPT: Introduction of Apache Ant.

Archival reference to the original embed shortcode:

{slideshare}[slideshare id=1117750&doc=introductiontoant1-090308134214-phpapp01]{/slideshare}

What Apache Ant does well

Ant uses an XML build file (typically build.xml) where you define explicit tasks and target dependencies. It is especially useful when you need precise control over build steps, custom file operations, or compatibility with existing enterprise Java projects.

  • Task-oriented: You define exactly what happens and in what order.
  • Extensible: You can use built-in tasks or add custom tasks.
  • Scriptable in CI: Ant is straightforward to execute from any runner that can run shell commands.

Core concepts: project, targets, tasks, and properties

  • Project: The root element of an Ant build file.
  • Target: A named stage (for example, compile or package) that can depend on other targets.
  • Task: An action inside a target (for example, javac, copy, jar).
  • Property: A key-value setting reused across the build (for example, directory paths).

Minimal build.xml example

This sample compiles Java source and creates a JAR artifact. It is intentionally small so you can adapt it quickly.

<project name="sample-ant-app" default="package" basedir=".">
    <property name="src.dir" value="src"/>
    <property name="build.dir" value="build"/>
    <property name="dist.dir" value="dist"/>

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

    <target name="compile">
        <mkdir dir="${build.dir}"/>
        <javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false"/>
    </target>

    <target name="package" depends="compile">
        <mkdir dir="${dist.dir}"/>
        <jar destfile="${dist.dir}/app.jar" basedir="${build.dir}"/>
    </target>
</project>Code language: HTML, XML (xml)

How an Ant build executes

flowchart TD
    A[Run ant package] --> B[Read build.xml]
    B --> C[Resolve target dependencies]
    C --> D[Run compile tasks]
    D --> E{Compile succeeded}
    E -- no --> F[Stop and report error]
    E -- yes --> G[Run package target]
    G --> H[Write artifact to dist]

Common Ant commands

CommandPurposeTypical use
ant -pList available targetsDiscover runnable stages in a project
ant cleanRun cleanup targetRemove previous build outputs
ant compileCompile source codeFast validation in local development
ant packageCreate distributable artifactProduce JAR or WAR before deploy
ant -Denv=prod packageSet runtime propertySwitch behavior by environment
# Show targets
ant -p

# Clean and build
ant clean package

# Pass a property
ant -Denv=prod packageCode language: PHP (php)

Ant vs Maven vs Gradle

These tools all build Java projects, but they differ in how much convention they impose and how you express build logic.

ToolBuild styleDependency managementBest for
Apache AntImperative, task-by-task controlPossible, but not the primary design focusCustom workflows and legacy build systems
Apache MavenDeclarative lifecycle with conventionsBuilt-in and central to workflowStandardized enterprise Java builds
GradleProgrammable DSL plus conventionsBuilt-in and flexibleComplex multi-module or highly customized modern builds

Using Ant in CI/CD pipelines

At minimum, a CI job needs Java and Ant installed, then executes target commands the same way you do locally. Keep outputs in a predictable directory (such as dist/) so artifacts can be archived or deployed.

stages:
  - build

build_with_ant:
  stage: build
  script:
    - ant clean package
  artifacts:
    paths:
      - dist/

Best practices and common pitfalls

  • Keep target names clear and action-oriented (clean, compile, test, package).
  • Avoid hidden side effects between targets; make dependencies explicit with depends.
  • Externalize environment differences with properties instead of hardcoding paths.
  • Use a consistent artifact output directory for CI/CD traceability.
  • Document required tools (JDK and Ant) to reduce onboarding friction and pipeline drift.

If you inherit an Ant-based system, first make the target graph reproducible and observable; then evaluate whether migration to Maven or Gradle is worth the effort.

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