Originally published on 2010-04-14; fully revised and updated.
Apache Ant still appears in many enterprise Java build and release pipelines. This guide focuses on five high-impact tasks from the original post—zip, concat, replaceregexp, checksum, and fail—with clear attribute summaries and corrected, usable examples.

What this reference covers
- zip: package files and archives with include/exclude and update behavior
- concat: merge text (or resources) into one output stream or file
- replaceregexp: apply regex-based edits across one or many files
- checksum: generate or verify digests for artifacts
- fail: stop builds intentionally when guard conditions are not met
How these tasks fit into an Ant build workflow
A common pattern is to package, normalize, validate, and then enforce quality gates before publishing artifacts.
flowchart LR
A[Collect build outputs] --> B[zip package artifacts]
B --> C[concat combine text resources]
C --> D[replaceregexp normalize content]
D --> E[checksum generate or verify]
E --> F{Validation passed}
F -- no --> G[fail stop build]
F -- yes --> H[Publish artifact]
Quick comparison of the five tasks
| Task | Primary use | Important attributes | Typical risk if misconfigured |
|---|---|---|---|
| zip | Create or update ZIP archives | destfile, basedir, includes/excludes, update, duplicate, whenempty | Duplicate entries, wrong file set, charset issues |
| concat | Concatenate resources to file/console | destfile, append, force, encoding, outputencoding, fixlastline | Unexpected rewrites, mixed encodings, broken line endings |
| replaceregexp | Regex replacement in files | match, replace, flags, byline, encoding | Over-broad substitutions, multiline surprises |
| checksum | Digest generation and verification | algorithm, fileext, property, verifyproperty, todir | Weak algorithm choices, ambiguous verify semantics |
| fail | Stop build with explicit reason | message, if, unless, status | Silent pipeline continuation when checks are missing |
Apache Ant zip task
The zip task creates ZIP archives and supports include/exclude patterns and nested file sets. The original reference also notes ZIP timestamp granularity (2 seconds), default duplicate handling (add), and that filename encoding defaults to the platform encoding unless set explicitly.
| Attribute | What it controls | Default / note |
|---|---|---|
| destfile | Output ZIP file path | Preferred attribute (zipfile is deprecated) |
| basedir | Base directory to package | Optional when nested filesets are used |
| includes / excludes | Pattern-based file selection | Supports includesfile/excludesfile |
| update | Update existing archive instead of overwrite mode | Default false |
| whenempty | Behavior when no files match | skip (default), fail, create |
| duplicate | Behavior for duplicate paths in archive | add (default), preserve, fail |
| encoding | Filename encoding inside archive | Default platform encoding |
| roundup | Round file timestamps to ZIP granularity | Default true |
| level | Compression level 0..9 | Available since Ant 1.7 (per original reference) |
<zip destfile="${dist}/manual.zip" basedir="htdocs/manual"/>
<zip destfile="${dist}/manual.zip" basedir="htdocs/manual" update="true"/>
<zip destfile="${dist}/docs.zip" encoding="UTF8" duplicate="fail" whenempty="fail">
<fileset dir="htdocs/manual" includes="api/**/*.html" excludes="**/todo.html"/>
</zip>Code language: HTML, XML (xml)
For encoding values, the original article pointed to the historical Java encoding list: http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html.
Apache Ant concat task
concat merges one or more resources into a single destination file, or writes to the console if no destination is given. The original reference notes behavior for append, force, encoding, and line ending normalization.
| Attribute | Purpose | Default / note |
|---|---|---|
| destfile | Output file | If omitted, output goes to console |
| append | Append to existing destination | no |
| force | Write even when destination is newer | yes |
| encoding | Input encoding | Platform default |
| outputencoding | Output encoding | encoding value or JVM default |
| fixlastline / eol | Normalize final newline per input | fixlastline defaults to no |
<concat>
<fileset dir="${src}" includes="**/*.txt"/>
</concat>
<concat destfile="${dist}/combined.xml"
append="false"
force="no"
fixlastline="true"
eol="lf"
outputencoding="UTF-8">
<filelist dir="${src}" files="introduction.xml,overview.xml"/>
<fileset dir="${src}/sections" includes="*.xml" excludes="introduction.xml,overview.xml"/>
</concat>Code language: HTML, XML (xml)
Apache Ant replaceregexp task
replaceregexp applies regex-based replacements to one file or a selected file set. Per the original notes, Ant writes output only when content changes, which helps avoid unnecessary rebuild churn.
Common flags supported in the original reference:
- g: replace all matches
- i: case-insensitive match
- m: multiline mode
- s: single-line mode where dot can match newline
<replaceregexp file="${src}/build.properties"
match="OldProperty=(.*)"
replace="NewProperty=\1"
byline="true"/>
<replaceregexp match="\s+" replace=" " flags="g" byline="false">
<fileset dir="." includes="**/*.properties"/>
</replaceregexp>Code language: HTML, XML (xml)
Apache Ant checksum task
checksum generates digest files or verifies existing digests. The source explicitly warns that MD5 and SHA-1 are broken for security-sensitive uses; if integrity checks are security-critical, evaluate stronger algorithms available from your JCE provider.
| Attribute or mode | Behavior | Important detail |
|---|---|---|
| algorithm | Select digest algorithm | Default MD5 in original reference |
| fileext | Output extension for checksum file | Default uses algorithm name casing |
| property | Generated checksum value or expected value | Meaning changes when verifyproperty is set |
| verifyproperty | Set true/false based on checksum match | No checksum file/property written in verify mode |
| todir | Directory for checksum outputs | If omitted, checksum file is near source file |
| format value | Pattern | Description |
|---|---|---|
| CHECKSUM | {0} | Checksum only |
| MD5SUM | {0} *{1} | GNU textutils style |
| SVF | MD5 ({1}) = {0} | BSD md5 style |
<checksum file="foo.bar" algorithm="MD5"/>
<checksum file="foo.bar" algorithm="MD5" forceoverwrite="yes"/>
<checksum file="foo.bar" property="foobarMD5"/>
<checksum file="foo.bar" verifyproperty="isMD5ok"/>
<checksum file="foo.bar" property="${expected.md5}" verifyproperty="isEqual"/>Code language: HTML, XML (xml)
Apache Ant fail task
fail aborts the current build with a clear message. It is commonly used as a quality gate with if / unless conditions and can optionally set an exit status.
<fail message="Something wrong here."/>
<fail unless="release.ready" message="Release prerequisites not met" status="2"/>
<condition property="required.files.missing">
<or>
<not><available file="one.txt"/></not>
<not><available file="two.txt"/></not>
</or>
</condition>
<fail if="required.files.missing" message="one.txt and two.txt must exist."/>Code language: HTML, XML (xml)
Version notes preserved from the original reference
- zip: Unix permission storage in archive was noted from Ant 1.5.2.
- zip: roundup noted from Ant 1.6.2; comment from 1.6.3; level from 1.7.
- concat: resource collection behavior noted from Ant 1.7.1.
- fail: status attribute noted from Ant 1.6.2.
Common pitfalls and best practices
- Set zip duplicate to fail or preserve unless duplicate paths are intentional.
- Use explicit encoding for zip and concat in mixed-platform teams.
- Treat checksum property + verifyproperty carefully; semantics differ between generate and verify modes.
- Use fail for guardrails (missing files, missing environment state) so bad builds stop early.
- Keep regex replacements narrow (scoped filesets + tested patterns) to avoid mass accidental edits.
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.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals
Apache Ant Comments and echo Task: Write Clear build.xml Files and Control Log Output
Learn the correct way to add comments in Apache Ant and when to use the echo task instead. This guide covers echo attributes, log-level behavior, and practical build.xml examples.