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 Task Reference for DevOps: zip, concat, replaceregexp, checksum, and fail

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.

Apache Ant complete task reference

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

TaskPrimary useImportant attributesTypical risk if misconfigured
zipCreate or update ZIP archivesdestfile, basedir, includes/excludes, update, duplicate, whenemptyDuplicate entries, wrong file set, charset issues
concatConcatenate resources to file/consoledestfile, append, force, encoding, outputencoding, fixlastlineUnexpected rewrites, mixed encodings, broken line endings
replaceregexpRegex replacement in filesmatch, replace, flags, byline, encodingOver-broad substitutions, multiline surprises
checksumDigest generation and verificationalgorithm, fileext, property, verifyproperty, todirWeak algorithm choices, ambiguous verify semantics
failStop build with explicit reasonmessage, if, unless, statusSilent 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.

AttributeWhat it controlsDefault / note
destfileOutput ZIP file pathPreferred attribute (zipfile is deprecated)
basedirBase directory to packageOptional when nested filesets are used
includes / excludesPattern-based file selectionSupports includesfile/excludesfile
updateUpdate existing archive instead of overwrite modeDefault false
whenemptyBehavior when no files matchskip (default), fail, create
duplicateBehavior for duplicate paths in archiveadd (default), preserve, fail
encodingFilename encoding inside archiveDefault platform encoding
roundupRound file timestamps to ZIP granularityDefault true
levelCompression level 0..9Available 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.

AttributePurposeDefault / note
destfileOutput fileIf omitted, output goes to console
appendAppend to existing destinationno
forceWrite even when destination is neweryes
encodingInput encodingPlatform default
outputencodingOutput encodingencoding value or JVM default
fixlastline / eolNormalize final newline per inputfixlastline 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 modeBehaviorImportant detail
algorithmSelect digest algorithmDefault MD5 in original reference
fileextOutput extension for checksum fileDefault uses algorithm name casing
propertyGenerated checksum value or expected valueMeaning changes when verifyproperty is set
verifypropertySet true/false based on checksum matchNo checksum file/property written in verify mode
todirDirectory for checksum outputsIf omitted, checksum file is near source file
format valuePatternDescription
CHECKSUM{0}Checksum only
MD5SUM{0} *{1}GNU textutils style
SVFMD5 ({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.

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

Apache Ant Interview Questions Answered: Concepts, build.xml Examples, and Practical Snippets

This guide converts a long Apache Ant interview question list into clear, practical answers with working build.xml examples. It covers core Ant concepts, common tasks, debugging, and Ant vs Maven vs Make.

Read More

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.

Read More

How to Run Ant Builds in IntelliJ IDEA: Setup, Troubleshooting, and Copy Task Patterns

This guide shows how to integrate a build.xml file with IntelliJ IDEA, run Ant targets from the IDE, and troubleshoot common environment-variable issues. It also compares practical Ant copy/fileset patterns with reusable examples.

Read More

Apache Ant clean, prepare, and compile Targets: A Practical build.xml Walkthrough

Learn how to structure a simple Ant build pipeline using clean, prepare, and compile targets with explicit dependencies. This revision includes a complete build.xml example, execution commands, and a workflow diagram.

Read More

Apache Ant Copy Task Examples: File, FileSet, Include/Exclude, and Flatten Patterns

Learn practical Apache Ant copy task patterns for real build pipelines, from single-file copies to filtered FileSets and flattened library bundles. Includes reusable XML snippets and a workflow diagram.

Read More

Apache Ant Dependency Visualization: AntScript Visualizer, Grand, and Vizant

A practical, updated guide to three classic Apache Ant visualization tools and how they help you understand target dependencies. Includes a side-by-side comparison, workflow diagram, and example commands.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x