{"id":134,"date":"2026-10-12T11:31:32","date_gmt":"2026-10-12T11:31:32","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2009\/06\/20\/copy-and-include-issues-in-apache-ant\/"},"modified":"2026-10-12T11:31:32","modified_gmt":"2026-10-12T11:31:32","slug":"copy-and-include-issues-in-apache-ant","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/copy-and-include-issues-in-apache-ant\/","title":{"rendered":"Apache Ant copy\/fileset Include Pitfall: Why One Syntax Fails and How to Fix It"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Originally published on 2009-06-20; fully revised and updated.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains a common Apache Ant <code>copy<\/code>\/<code>fileset<\/code> troubleshooting case: one include style appears to fail while another works. If you maintain legacy Ant build files, this will help you understand how include patterns are interpreted and how to make file-copy targets deterministic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The original question and examples came from <a href=\"https:\/\/www.devopsschool.com\/blog\/copy-and-include-issues-in-apache-ant\/\">this post<\/a>, using Apache Ant version 1.5.4.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"400\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2009\/06\/issues-in-apache-ant.png\" alt=\"Original Apache Ant copy\/include issue screenshot\" class=\"wp-image-4054\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2009\/06\/issues-in-apache-ant.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2009\/06\/issues-in-apache-ant-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>Original example image from the 2009 troubleshooting post.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Problem statement and observed behavior<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The reported issue: a <code>copy<\/code> task with a nested <code>&lt;include name=\"...\"\/&gt;<\/code> did not copy files, while a self-closing <code>fileset<\/code> using an <code>includes<\/code> attribute did work, even though the file names looked the same.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Approach<\/th><th>Syntax style<\/th><th>How Ant interprets it<\/th><th>Likely result<\/th><\/tr><\/thead><tbody><tr><td>Program 1<\/td><td>One nested <code>include<\/code> element containing a comma-separated string in <code>name<\/code><\/td><td>Treated as one pattern string<\/td><td>No match (or unexpected match)<\/td><\/tr><tr><td>Program 2<\/td><td><code>includes<\/code> attribute on <code>fileset<\/code> with comma-separated list<\/td><td>Treated as a list of patterns<\/td><td>Expected files copied<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why Program 1 can fail while Program 2 works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The key difference is <strong>pattern list parsing<\/strong>. In Ant, a nested <code>&lt;include&gt;<\/code> typically represents one pattern per element, while the <code>includes<\/code> attribute supports a list format. So this is not just visual syntax variation; it changes how the matcher receives patterns. See the Ant manual for <a href=\"https:\/\/ant.apache.org\/manual\/Types\/fileset.html\">FileSet<\/a> and <a href=\"https:\/\/ant.apache.org\/manual\/Types\/patternset.html\">PatternSet<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use multiple nested <code>&lt;include name=\"...\"\/&gt;<\/code> entries if you choose nested form.<\/li><li>Use <code>includes=\"a,b,c\"<\/code> when you want one-line list syntax.<\/li><li>Be careful with exact file names, case sensitivity, and relative directory paths.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Correct ways to specify multiple include patterns<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Option A: Use the includes attribute (compact form)<\/h3>\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\">copy<\/span> <span class=\"hljs-attr\">todir<\/span>=<span class=\"hljs-string\">\"${Temp}\/uaw\/Uaw_compilescripts\"<\/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\">\"${SVNCheckout}\/scripts\/compilescripts\"<\/span>\n             <span class=\"hljs-attr\">includes<\/span>=<span class=\"hljs-string\">\"BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1\"<\/span>\/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">copy<\/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<h3 class=\"wp-block-heading\">Option B: Use multiple nested include elements (explicit form)<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" 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\">copy<\/span> <span class=\"hljs-attr\">todir<\/span>=<span class=\"hljs-string\">\"${Temp}\/uaw\/Uaw_compilescripts\"<\/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\">\"${SVNCheckout}\/scripts\/compilescripts\"<\/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\">\"BuildSh\"<\/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\">\"Compsh\"<\/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\">\"vsamc\"<\/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\">\"buildc.sh\"<\/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\">\"script\"<\/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\">\"compl2\"<\/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\">\"main.sh\"<\/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\">\"makefile\"<\/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\">\"makepl1\"<\/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\">copy<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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<h3 class=\"wp-block-heading\">Optional: wildcard-based patterns for maintainability<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" 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\">copy<\/span> <span class=\"hljs-attr\">todir<\/span>=<span class=\"hljs-string\">\"${Temp}\/uaw\/Uaw_compilescripts\"<\/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\">\"${SVNCheckout}\/scripts\/compilescripts\"<\/span>\n             <span class=\"hljs-attr\">includes<\/span>=<span class=\"hljs-string\">\"**\/*.sh,**\/makefile\"<\/span>\/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">copy<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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\">How Ant processes file selection in copy tasks<\/h2>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Define copy task] --> B[Create fileset]\n    B --> C{Include style}\n    C --> D[includes attribute list]\n    C --> E[nested include elements]\n    D --> F[Split into patterns]\n    E --> G{Single include contains commas}\n    G -- yes --> H[Treated as one pattern]\n    G -- no --> I[Each include is one pattern]\n    F --> J[Match files under dir]\n    H --> J\n    I --> J\n    J --> K{Any files matched}\n    K -- no --> L[No files copied]\n    K -- yes --> M[Files copied]\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting commands and checks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When results are unexpected, run Ant with extra logging and verify resolved property values.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs language-bash\">ant -version\nant -verbose your-target\nant -d your-target<\/code><\/span><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" 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\">echo<\/span> <span class=\"hljs-attr\">message<\/span>=<span class=\"hljs-string\">\"SVNCheckout=${SVNCheckout}\"<\/span>\/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">echo<\/span> <span class=\"hljs-attr\">message<\/span>=<span class=\"hljs-string\">\"Temp=${Temp}\"<\/span>\/&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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<ul class=\"wp-block-list\"><li>Confirm the <code>fileset dir<\/code> exists at runtime.<\/li><li>Check case sensitivity of file names on your OS\/filesystem.<\/li><li>Avoid combining many literal names into a single nested <code>include name<\/code>.<\/li><li>Remove duplicates (for example, <code>script<\/code> listed twice) to keep intent clear.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Prefer <strong>one pattern per nested include element<\/strong> when using nested syntax.<\/li><li>Use the <strong>includes attribute<\/strong> for concise pattern lists.<\/li><li>Add temporary <code>echo<\/code> statements and run with <code>-verbose<\/code> during debugging.<\/li><li>Keep include patterns simple and predictable; move complex matching into well-named pattern sets.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>If your Ant <copy> task works with an includes attribute but fails with nested <include>, the issue is usually pattern parsing. This guide explains the difference, shows correct syntax, and gives practical troubleshooting steps.<\/p>\n","protected":false},"author":1,"featured_media":4054,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[12],"tags":[209,3196,3197,3200,3201,683,3195,3193,3194,2881,2882,2520,3191,3199,3190,3202,3192,3189,255,1028,3198],"class_list":["post-134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache-ant","tag-ant","tag-ant-copy-and-include-issue-troubleshooting","tag-ant-copy-issue-troubleshooting-guide","tag-ant-troubleshooting","tag-ant-troubleshooting-guide","tag-apache-ant","tag-apache-ant-copy-and-include-issue","tag-apache-ant-copy-issue","tag-apache-ant-copy-toubleshoot","tag-apache-ant-guide","tag-apache-ant-tutorial","tag-copy","tag-copy-and-include-issue-in-ant","tag-copy-in-ant-is-not-working","tag-copy-issue","tag-copy-issue-in-apache-ant","tag-copy-problem","tag-include","tag-issues","tag-problems","tag-program"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/134","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=134"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":78983,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/134\/revisions\/78983"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4054"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}