MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Apache Ant Copy + FileSet Include Issue: Why Comma-Separated include name Fails

If your Apache Ant <copy> task seems to skip files when you use <include>, the problem is usually pattern syntax, not the copy task itself. This guide explains why one style fails, why the other works, and how to write include rules that are predictable.

Originally published on 2009-06-20; fully revised and updated.

Source scenario: DevOpsSchool original post.

Apache Ant copy and include issue

Why Program 1 fails and Program 2 works

In a <fileset>, a nested <include name="..."/> expects one pattern per include element. It does not automatically split a comma-separated string into many names. By contrast, the includes="..." attribute supports a list, so comma-separated values are parsed as multiple patterns.

Failing style (single nested include with commas)

<copy todir="${Temp}/uaw/Uaw_compilescripts">
    <fileset dir="${SVNCheckout}/scripts/compilescripts">
        <include name="BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script"/>
    </fileset>
</copy>Code language: HTML, XML (xml)

This is treated as one literal pattern string. Unless a real filename matches that entire comma-joined value, no files are copied.

Working styles

<!-- Option A: one nested include per pattern -->
<copy todir="${Temp}/uaw/Uaw_compilescripts">
    <fileset dir="${SVNCheckout}/scripts/compilescripts">
        <include name="BuildSh"/>
        <include name="Compsh"/>
        <include name="vsamc"/>
        <include name="buildc.sh"/>
        <include name="script"/>
        <include name="compl2"/>
        <include name="main.sh"/>
        <include name="makefile"/>
        <include name="makepl1"/>
    </fileset>
</copy>

<!-- Option B: includes attribute with a list -->
<copy todir="${Temp}/uaw/Uaw_compilescripts">
    <fileset dir="${SVNCheckout}/scripts/compilescripts"
             includes="BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1"/>
</copy>Code language: HTML, XML (xml)

How Ant processes include patterns

flowchart TD
    A[copy task runs] --> B[fileset reads base directory]
    B --> C{Pattern source}
    C --> D[includes attribute list]
    C --> E[nested include elements]
    D --> F[List split into multiple patterns]
    E --> G[Each include name is one pattern]
    F --> H[Matching files copied]
    G --> I[Comma joined name usually no match]
    I --> J[Copy seems to fail]

Comparison of include approaches

ApproachExample syntaxHow patterns are interpretedTypical result
Nested include with comma list<include name=”a,b,c”/>Single pattern stringUsually no matches
Nested include, one per item<include name=”a”/> then <include name=”b”/>Each include is evaluated separatelyWorks as expected
includes attribute listincludes=”a,b,c”List is split into multiple patternsWorks as expected

Debugging and verification commands

When copy behavior is unclear, run Ant in verbose or debug mode to inspect resolved file patterns and copied files.

ant -v copy-scripts
ant -d copy-scripts
<target name="copy-scripts">
    <copy todir="${Temp}/uaw/Uaw_compilescripts" overwrite="true">
        <fileset dir="${SVNCheckout}/scripts/compilescripts"
                 includes="BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1"/>
    </copy>
</target>Code language: HTML, XML (xml)

Best practices

  • Use includes="..." for compact lists, or one nested <include> per pattern.
  • Avoid duplicates in include lists (for example, repeated script entries) to keep builds readable.
  • Prefer explicit filenames or well-scoped wildcards so copy behavior is deterministic.
  • Use ant -v or ant -d whenever file selection does not match expectations.

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

Jenkins Build and Release Training Blueprint: Git/SVN with Maven and Ant

This revised guide turns a legacy training announcement into a practical learning blueprint for build-and-release engineering. It maps the Jenkins workflow, compares core tools, and includes realistic command and pipeline examples.

Read More

Gradle for DevOps: Core Concepts, Build Workflow, and Practical Examples

Gradle is a flexible build automation tool used to compile, test, package, and publish software in repeatable pipelines. This guide explains how Gradle works, how it compares with Maven and Ant, and how to start with practical commands.

Read More

Apache Ant Training Guide: Curriculum, Build Workflow, and Hands-On Labs

Use this structured Apache Ant training guide to evaluate or design an Ant-focused course for Java build and release engineering. It summarizes the curriculum, demonstrates a realistic build.xml workflow, and compares Ant with Maven and Gradle.

Read More

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

Maven vs Ant: Key Differences, Build Workflow, and When to Use Each

Maven and Ant both automate Java builds, but they use very different models. This guide compares their workflows, configuration style, and CI implications with practical examples.

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
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

Apache Ant copy and include issues can often come from incorrect paths or unexpected file patterns. Checking the source and destination directories first helps narrow down the cause. It is also useful to review include and exclude rules carefully, since one small pattern can change which files get copied. Running the target with clear logging makes it easier to see what Ant actually processes. These checks help keep build scripts predictable and prevent missing files from reaching later stages.

Jason Mitchell
Jason Mitchell
4 months ago

In enterprise build environments, file selection problems are often symptoms of a larger challenge around artifact consistency. When different teams modify build scripts over time, there is a risk of creating hidden dependencies on folder structures or naming conventions that are not documented anywhere. A good practice is to treat generated artifacts as testable outputs by adding checks for file integrity, expected contents, and version consistency before they move to later stages of the pipeline. This helps catch packaging issues early and avoids situations where deployments succeed technically but fail due to incomplete or incorrect artifacts.

2
0
Would love your thoughts, please comment.x
()
x