{"id":218,"date":"2026-10-12T23:30:50","date_gmt":"2026-10-12T23:30:50","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/03\/21\/power-point-ppt-apache-ant-2\/"},"modified":"2026-10-12T23:30:50","modified_gmt":"2026-10-12T23:30:50","slug":"power-point-ppt-apache-ant-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/power-point-ppt-apache-ant-2\/","title":{"rendered":"Apache Ant for DevOps: build.xml Fundamentals, Workflow, and Practical Commands"},"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\">This page upgrades the <a href=\"https:\/\/www.devopsschool.com\/blog\/power-point-ppt-apache-ant-2\/\">original Apache Ant slides post<\/a> 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.<\/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\">Apache Ant is an XML-based build automation tool, widely used in Java ecosystems. It gives you explicit control over build steps through a <code>build.xml<\/code> file, where you define targets and their dependencies.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use Ant when you need <strong>fine-grained, imperative control<\/strong> of build steps.<\/li><li>Use it for legacy Java projects that already rely on Ant targets\/tasks.<\/li><li>Use it when pipeline steps map naturally to custom XML tasks and target chains.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Core concepts in an Ant build file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ant builds are usually defined in a single <code>build.xml<\/code> file. The most important elements are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>project<\/strong>: root element with project name and default target.<\/li><li><strong>target<\/strong>: named unit of work (for example <code>clean<\/code>, <code>compile<\/code>, <code>jar<\/code>).<\/li><li><strong>depends<\/strong>: target dependency chain controlling execution order.<\/li><li><strong>task<\/strong>: atomic action such as <code>mkdir<\/code>, <code>javac<\/code>, <code>jar<\/code>, <code>delete<\/code>.<\/li><li><strong>property<\/strong>: reusable key\/value setting for directories, filenames, and flags.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How target execution flows in Ant<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Run ant jar] --> B[Load build.xml and properties]\n    B --> C[Resolve target dependencies]\n    C --> D[Run clean]\n    D --> E[Run compile]\n    E --> F{Compile successful}\n    F -- yes --> G[Run jar]\n    F -- no --> H[Stop build and report failure]\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 shows a small but realistic Ant setup with clean, compile, and jar targets.<\/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\">\"jar\"<\/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    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"jar.file\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"${dist.dir}\/demo-ant.jar\"<\/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\">\"init\"<\/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\">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\">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,init\"<\/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\">\"jar\"<\/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\">jar<\/span> <span class=\"hljs-attr\">destfile<\/span>=<span class=\"hljs-string\">\"${jar.file}\"<\/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 CLI commands<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These commands are commonly used in local builds and CI jobs.<\/p>\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\"># Show available targets<\/span>\nant -p\n\n<span class=\"hljs-comment\"># Run a specific target<\/span>\nant clean\nant compile\nant jar\n\n<span class=\"hljs-comment\"># Run with an explicit build file<\/span>\nant -f build.xml jar\n\n<span class=\"hljs-comment\"># Override a property from CLI<\/span>\nant -Dbuild.dir=out jar<\/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\">Ant vs Maven vs Gradle<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">All three tools automate builds, but they differ in model and ergonomics.<\/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>Best for<\/th><th>Trade-offs<\/th><\/tr><\/thead><tbody><tr><td>Apache Ant<\/td><td>Imperative XML targets\/tasks<\/td><td>Custom, step-by-step control and legacy Java builds<\/td><td>More manual setup; fewer conventions out of the box<\/td><\/tr><tr><td>Maven<\/td><td>Convention-driven lifecycle with POM<\/td><td>Standardized Java project structures and dependency workflows<\/td><td>Less flexible for unusual build logic without extra plugins\/config<\/td><\/tr><tr><td>Gradle<\/td><td>Declarative + programmable build scripts<\/td><td>Complex multi-module builds and modern automation patterns<\/td><td>Higher scripting complexity for teams that prefer strict conventions<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Original Slideshare embed token from the source post<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original article was a short Slideshare embed. If your WordPress site still supports that shortcode, this is the original token from the post:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json language-text\">&#91;slideshare id=<span class=\"hljs-number\">1117746<\/span>&amp;doc=apacheant<span class=\"hljs-number\">-090308134221<\/span>-phpapp01]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/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 dependencies for flow.<\/li><li>Centralize paths and constants in <code>property<\/code> definitions.<\/li><li>Name targets clearly (<code>clean<\/code>, <code>compile<\/code>, <code>test<\/code>, <code>package<\/code>) to aid CI readability.<\/li><li>Avoid hidden side effects between targets; each target should be predictable.<\/li><li>Document required JDK\/tools in repository docs so CI and local builds stay consistent.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This revised guide explains Apache Ant as a practical build automation tool for Java projects. It covers Ant\u2019s core concepts, execution flow, CLI usage, and a side-by-side comparison 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-218","post","type-post","status-publish","format-standard","hentry","category-training"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/218","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=218"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":79058,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions\/79058"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}