{"id":219,"date":"2026-10-12T22:31:04","date_gmt":"2026-10-12T22:31:04","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/03\/21\/power-point-ppt-introduction-to-ant-2\/"},"modified":"2026-10-12T22:31:04","modified_gmt":"2026-10-12T22:31:04","slug":"power-point-ppt-introduction-to-ant-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/power-point-ppt-introduction-to-ant-2\/","title":{"rendered":"Apache Ant Introduction: build.xml Basics, Commands, and CI Workflow"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Originally published on 2010-03-21; fully revised and updated.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Ant is a build automation tool most commonly associated with Java projects, especially legacy or highly customized build pipelines. This guide is for DevOps and platform engineers who need to read, run, troubleshoot, or modernize Ant builds in CI\/CD environments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/www.devopsschool.com\/blog\/power-point-ppt-introduction-to-ant-2\/\">original post<\/a> was a short SlideShare embed reference (id: 1117751). This revision provides a complete standalone introduction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Apache Ant is and when to use it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ant uses an XML file (usually <code>build.xml<\/code>) to define build logic as named targets made up of tasks. It is especially useful when you need explicit, step-by-step control instead of convention-driven defaults.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Good fit:<\/strong> legacy Java applications, custom packaging logic, migration phases, and non-standard build steps.<\/li><li><strong>Less ideal:<\/strong> teams that prefer strong conventions and built-in dependency lifecycle management.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Ant core concepts in build.xml<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Concept<\/th><th>What it means<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Project<\/td><td>Top-level build definition<\/td><td><code>&lt;project name=\"demo\" default=\"package\"&gt;<\/code><\/td><\/tr><tr><td>Target<\/td><td>A named stage in the build<\/td><td><code>&lt;target name=\"compile\"&gt;<\/code><\/td><\/tr><tr><td>Task<\/td><td>An executable unit inside a target<\/td><td><code>&lt;javac ... \/&gt;<\/code>, <code>&lt;copy ... \/&gt;<\/code><\/td><\/tr><tr><td>Property<\/td><td>Immutable key\/value setting<\/td><td><code>&lt;property name=\"src.dir\" value=\"src\"\/&gt;<\/code><\/td><\/tr><tr><td>depends<\/td><td>Target execution order<\/td><td><code>&lt;target name=\"package\" depends=\"test\"&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How an Ant build executes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you run an Ant command, Ant loads the project file, resolves properties, then executes the requested target and its dependencies in order.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Run ant command] --> B[Load build.xml]\n    B --> C[Resolve properties]\n    C --> D[Select target]\n    D --> E[Run dependent targets]\n    E --> F[Execute tasks]\n    F --> G[Build artifacts and reports]\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Minimal build.xml example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This example demonstrates a common flow: clean, compile, test placeholder, and package as a JAR.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">project<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"demo-ant\"<\/span> <span class=\"hljs-attr\">default<\/span>=<span class=\"hljs-string\">\"package\"<\/span> <span class=\"hljs-attr\">basedir<\/span>=<span class=\"hljs-string\">\".\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"src.dir\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"src\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"build.dir\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"build\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"classes.dir\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"${build.dir}\/classes\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"dist.dir\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"dist\"<\/span>\/&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">target<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"clean\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">delete<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"${build.dir}\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">delete<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"${dist.dir}\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">target<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">target<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"compile\"<\/span> <span class=\"hljs-attr\">depends<\/span>=<span class=\"hljs-string\">\"clean\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">mkdir<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"${classes.dir}\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">javac<\/span> <span class=\"hljs-attr\">srcdir<\/span>=<span class=\"hljs-string\">\"${src.dir}\"<\/span> <span class=\"hljs-attr\">destdir<\/span>=<span class=\"hljs-string\">\"${classes.dir}\"<\/span> <span class=\"hljs-attr\">includeantruntime<\/span>=<span class=\"hljs-string\">\"false\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">target<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">target<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"test\"<\/span> <span class=\"hljs-attr\">depends<\/span>=<span class=\"hljs-string\">\"compile\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">echo<\/span> <span class=\"hljs-attr\">message<\/span>=<span class=\"hljs-string\">\"Run unit tests here\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">target<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">target<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"package\"<\/span> <span class=\"hljs-attr\">depends<\/span>=<span class=\"hljs-string\">\"test\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">mkdir<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"${dist.dir}\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">jar<\/span> <span class=\"hljs-attr\">destfile<\/span>=<span class=\"hljs-string\">\"${dist.dir}\/app.jar\"<\/span> <span class=\"hljs-attr\">basedir<\/span>=<span class=\"hljs-string\">\"${classes.dir}\"<\/span>\/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">target<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">project<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Useful Ant commands for day-to-day work<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\"># List available targets<\/span>\nant -p\n\n<span class=\"hljs-comment\"># Run individual targets<\/span>\nant clean\nant compile\nant test\nant package\n\n<span class=\"hljs-comment\"># Pass a property at runtime<\/span>\nant package -Dskip.tests=<span class=\"hljs-keyword\">true<\/span>\n\n<span class=\"hljs-comment\"># Increase log detail<\/span>\nant -verbose package<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Frequently used built-in Ant tasks<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Task<\/th><th>Purpose<\/th><th>Typical usage<\/th><\/tr><\/thead><tbody><tr><td><code>mkdir<\/code><\/td><td>Create directories<\/td><td>Prepare build output paths<\/td><\/tr><tr><td><code>delete<\/code><\/td><td>Remove files\/directories<\/td><td>Clean previous artifacts<\/td><\/tr><tr><td><code>copy<\/code><\/td><td>Copy files\/resources<\/td><td>Move configs\/static assets into output<\/td><\/tr><tr><td><code>javac<\/code><\/td><td>Compile Java source<\/td><td>Build class files into a classes directory<\/td><\/tr><tr><td><code>jar<\/code><\/td><td>Create JAR archives<\/td><td>Package classes for distribution<\/td><\/tr><tr><td><code>echo<\/code><\/td><td>Print build messages<\/td><td>Debug and trace build flow<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Ant vs Maven vs Gradle<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These tools can overlap, but they optimize for different styles of build engineering.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Tool<\/th><th>Build style<\/th><th>Dependency management<\/th><th>Best fit<\/th><\/tr><\/thead><tbody><tr><td>Ant<\/td><td>Imperative (explicit targets\/tasks)<\/td><td>Not central by default; commonly handled with additional setup<\/td><td>Legacy systems or highly custom workflows<\/td><\/tr><tr><td>Maven<\/td><td>Convention and lifecycle driven<\/td><td>Built-in, standardized approach<\/td><td>Standardized Java application builds<\/td><\/tr><tr><td>Gradle<\/td><td>Declarative plus programmable DSL<\/td><td>Built-in, flexible<\/td><td>Teams needing convention with deeper customization<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Using Ant in CI pipelines<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most CI systems can run Ant directly in a shell step. Keep targets deterministic so local and CI behavior remain aligned.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript language-bash\"><span class=\"hljs-meta\">#!\/usr\/bin\/env bash<\/span>\n<span class=\"hljs-keyword\">set<\/span> -euo pipefail\n\nant clean\nant test\nant package -Dbuild.number=\"${BUILD_NUMBER:-local}<span class=\"hljs-string\">\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Best practices and common pitfalls<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Keep targets <strong>small and composable<\/strong>; use <code>depends<\/code> for ordering.<\/li><li>Centralize paths and settings in properties; avoid hard-coded directories.<\/li><li>Use clear artifact directories (<code>build\/<\/code>, <code>dist\/<\/code>) and clean them predictably.<\/li><li>Avoid hidden side effects across targets; deterministic builds are easier to debug in CI.<\/li><li>Document required tools (JDK, Ant, environment variables) alongside the build file.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For official documentation and task references, start with the Apache Ant project site: <a href=\"https:\/\/ant.apache.org\/\">https:\/\/ant.apache.org\/<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide explains Apache Ant for engineers who need to understand or maintain Ant-based builds. You will learn core concepts, command usage, a practical build.xml example, and how Ant compares with Maven and Gradle.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[8],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-training"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":79052,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions\/79052"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}