{"id":274,"date":"2010-07-22T11:04:10","date_gmt":"2010-07-22T11:04:10","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/07\/22\/samples-of-the-ant-copy-task\/"},"modified":"2017-12-28T04:03:28","modified_gmt":"2017-12-28T04:03:28","slug":"samples-of-the-ant-copy-task","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/samples-of-the-ant-copy-task\/","title":{"rendered":"Samples\/Examples of the Ant copy task &#8211; Guide"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4396 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/07\/ant-copy-task.png\" alt=\"ant-copy-task\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/ant-copy-task.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/ant-copy-task-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Samples of the Ant copy task<br \/>\n<\/strong><br \/>\n&lt;copy file=&#8221;${resources.dir}\/MANIFEST.MF&#8221; tofile=&#8221;${temp.dir.meta-inf}\/MANIFEST.MF&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/managed-beans.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/managed-beans.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/navigation-rules.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/navigation-rules.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/monitoring-managed-beans.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/monitoring-managed-beans.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/monitoring-navigation-rules.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/monitoring-navigation-rules.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/faces-config.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/faces-config.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/log4j.properties&#8221; tofile=&#8221;${temp.dir.classes}\/log4j.properties&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/commons-logging.properties&#8221; tofile=&#8221;${temp.dir.classes}\/commons-logging.properties&#8221; overwrite=&#8221;true&#8221; \/&gt;<\/p>\n<p>&lt;copy todir=&#8221;${temp.dir.classes}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${src.dir}&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/*.xml&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.xsl&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.properties&#8221;\/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/copy&gt;<\/p>\n<p>&lt;copy todir=&#8221;${dist}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${src}&#8221;<br \/>\nincludes=&#8221;**\/images\/*&#8221;<br \/>\nexcludes=&#8221;**\/*.gif&#8221;<br \/>\n\/&gt;<br \/>\n&lt;\/copy&gt;<\/p>\n<p><strong>This copies all files in directories called images that are located in the directory tree defined by ${src} to the destination directory defined by ${dist}, but excludes all *.gif files from the copy.<\/strong><\/p>\n<p>&lt;copy todir=&#8221;${dist}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${src}&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/images\/*&#8221;\/&gt;<br \/>\n&lt;exclude name=&#8221;**\/*.gif&#8221;\/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/copy&gt;<\/p>\n<p><strong>The same as the example above, but expressed using nested elements.<\/strong><\/p>\n<p>&lt;delete dir=&#8221;${dist}&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/images\/*&#8221;\/&gt;<br \/>\n&lt;exclude name=&#8221;**\/*.gif&#8221;\/&gt;<br \/>\n&lt;\/delete&gt;<\/p>\n<p><strong>Deleting the original set of files, the delete task can act as an implicit fileset.<\/strong><\/p>\n<p><strong>Flatten directories when performing an Ant copy<\/strong><br \/>\nHere&#8217;s a code snippet from an Ant build script where I begin with a hierarchical structure of jar files in my development environment, then flatten out all my lib subdirectories into one directory in my production environment when I copy all the jar files to my production library directory:<\/p>\n<p>&lt;!&#8211; build a temporary lib dir, and flatten out the jars into one folder &#8211;&gt;<\/p>\n<p>&lt;copy todir=&#8221;${temp.dir.lib}&#8221; flatten=&#8221;true&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${lib.dir}&#8221;&gt;<br \/>\n&lt;exclude name=&#8221;${cob.lib.dir}&#8221; \/&gt;<br \/>\n&lt;exclude name=&#8221;junit*&#8221; \/&gt;<br \/>\n&lt;include name=&#8221;**\/*.jar&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.zip&#8221;\/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/copy&gt;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Samples of the Ant copy task &lt;copy file=&#8221;${resources.dir}\/MANIFEST.MF&#8221; tofile=&#8221;${temp.dir.meta-inf}\/MANIFEST.MF&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/managed-beans.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/managed-beans.xml&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/navigation-rules.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/navigation-rules.xml&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/monitoring-managed-beans.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/monitoring-managed-beans.xml&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/monitoring-navigation-rules.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/monitoring-navigation-rules.xml&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/faces-config.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/faces-config.xml&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/log4j.properties&#8221; tofile=&#8221;${temp.dir.classes}\/log4j.properties&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy file=&#8221;${resources.dir}\/commons-logging.properties&#8221; tofile=&#8221;${temp.dir.classes}\/commons-logging.properties&#8221; overwrite=&#8221;true&#8221; \/&gt; &lt;copy todir=&#8221;${temp.dir.classes}&#8221;&gt; &lt;fileset dir=&#8221;${src.dir}&#8221;&gt; &lt;include name=&#8221;**\/*.xml&#8221;\/&gt; &lt;include name=&#8221;**\/*.xsl&#8221;\/&gt; &lt;include&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4396,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[12],"tags":[209,4193,4196,4190,4194,4192,4188,4195,4189,4191],"class_list":["post-274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache-ant","tag-ant","tag-ant-copy-task-examples","tag-ant-copy-task-guide","tag-ant-copy-task-samples","tag-ant-task-copy-delete-examples","tag-apache-ant-copy","tag-copy-task","tag-how-to-use-ant-copy-task","tag-samples","tag-samples-ant-copy-task"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/274","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=274"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":4398,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions\/4398"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4396"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}