{"id":220,"date":"2026-10-12T21:11:11","date_gmt":"2026-10-12T21:11:11","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/03\/21\/power-point-ppt-using-ant-to-build-j2-ee-application-2\/"},"modified":"2026-10-12T21:11:11","modified_gmt":"2026-10-12T21:11:11","slug":"power-point-ppt-using-ant-to-build-j2-ee-application-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/power-point-ppt-using-ant-to-build-j2-ee-application-2\/","title":{"rendered":"Using Apache Ant to Build and Package J2EE Applications (WAR\/EAR)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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 <code>build.xml<\/code> pattern, and CI-friendly command usage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Originally published on 2010-03-21; fully revised and updated.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Slide deck reference from the original post<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original article was a short embed-only post. The Slideshare shortcode is preserved below for archival continuity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">{slideshare}[slideshare id=1117755&amp;doc=usinganttobuildj2eeapplications-090308134153-phpapp02]{\/slideshare}<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Ant workflow maps to J2EE packaging<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart LR\n    A[Developer updates source] --> B[Run ant clean]\n    B --> C[Compile Java classes]\n    C --> D[Copy web resources]\n    D --> E[Build WAR file]\n    E --> F[Assemble EAR file]\n    F --> G[Publish artifact]\n    G --> H[Deploy to application server]\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Recommended project layout<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A predictable directory structure keeps Ant targets easy to read and maintain.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>src\/main\/java<\/code> for Java source files<\/li><li><code>src\/main\/webapp<\/code> for JSP\/static files and <code>WEB-INF\/web.xml<\/code><\/li><li><code>src\/main\/application<\/code> for EAR-level metadata such as <code>META-INF\/application.xml<\/code><\/li><li><code>lib<\/code> for third-party JAR dependencies used at compile\/package time<\/li><li><code>build<\/code> for intermediate output (classes, temp files)<\/li><li><code>dist<\/code> for final deployable artifacts (<code>.war<\/code>, <code>.ear<\/code>)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Example build.xml for compile, WAR, and EAR targets<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This example shows a straightforward target chain: <code>clean<\/code> \u2192 <code>compile<\/code> \u2192 <code>war<\/code> \u2192 <code>ear<\/code>.<\/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\">\"sample-j2ee-app\"<\/span> <span class=\"hljs-attr\">default<\/span>=<span class=\"hljs-string\">\"ear\"<\/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\/main\/java\"<\/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\">\"web.dir\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"src\/main\/webapp\"<\/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\">path<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"compile.classpath\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">fileset<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"lib\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">include<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"**\/*.jar\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">fileset<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">path<\/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\">\"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\">classpath<\/span> <span class=\"hljs-attr\">refid<\/span>=<span class=\"hljs-string\">\"compile.classpath\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">javac<\/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\">\"war\"<\/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\">war<\/span> <span class=\"hljs-attr\">destfile<\/span>=<span class=\"hljs-string\">\"${dist.dir}\/sample.war\"<\/span> <span class=\"hljs-attr\">webxml<\/span>=<span class=\"hljs-string\">\"${web.dir}\/WEB-INF\/web.xml\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">fileset<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"${web.dir}\"<\/span>\/&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">classes<\/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\">lib<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"lib\"<\/span>\/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">war<\/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\">\"ear\"<\/span> <span class=\"hljs-attr\">depends<\/span>=<span class=\"hljs-string\">\"war\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ear<\/span> <span class=\"hljs-attr\">destfile<\/span>=<span class=\"hljs-string\">\"${dist.dir}\/sample.ear\"<\/span> <span class=\"hljs-attr\">appxml<\/span>=<span class=\"hljs-string\">\"src\/main\/application\/META-INF\/application.xml\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">fileset<\/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\">include<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"sample.war\"<\/span>\/&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">fileset<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ear<\/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\">Run common Ant commands<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use explicit targets in local development and CI so the build path is predictable.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs language-bash\">ant clean\nant compile\nant war\nant ear\nant -Dbuild.number=20261012 ear<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Ant vs Maven vs Gradle at a glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you are deciding whether to keep Ant or migrate, compare the build model and operational trade-offs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Tool<\/th><th>Build definition style<\/th><th>Dependency handling<\/th><th>Typical fit<\/th><\/tr><\/thead><tbody><tr><td>Ant<\/td><td>Explicit XML targets and task order<\/td><td>Manual management or add-on tooling<\/td><td>Legacy builds needing fine-grained task control<\/td><\/tr><tr><td>Maven<\/td><td>Convention-based lifecycle (POM)<\/td><td>Built-in repository-driven model<\/td><td>Teams preferring standard Java conventions<\/td><\/tr><tr><td>Gradle<\/td><td>Scripted DSL with tasks and plugins<\/td><td>Built-in repository-driven model<\/td><td>Flexible multi-module builds and custom automation<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common pitfalls and best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Keep artifact assembly deterministic: avoid hidden local dependencies outside <code>lib<\/code> or repository config.<\/li><li>Use clear target dependencies so <code>ant ear<\/code> always implies compile and WAR creation.<\/li><li>Parameterize environment-specific values with properties files instead of editing <code>build.xml<\/code> per environment.<\/li><li>Treat <code>dist<\/code> output as immutable deployment artifacts once built.<\/li><li>Document expected JDK level and app-server requirements alongside the build file.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This revised guide explains how to use Apache Ant to compile Java code and package J2EE applications into WAR and EAR artifacts. It includes a practical workflow diagram, a reusable build.xml example, command usage, and a 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-220","post","type-post","status-publish","format-standard","hentry","category-training"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/220","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=220"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":79044,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/220\/revisions\/79044"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}