<tar tarfile="${dist}/manual.tar" basedir="htdocs/manual"/> <gzip zipfile="${dist}/manual.tar.gz" src="${dist}/manual.tar"/>tars all files in the htdocs/manual directory into a file called manual.tar in the ${dist} directory, then applies the gzip task to compress it.
<tar destfile="${dist}/manual.tar" basedir="htdocs/manual" excludes="mydocs/**, **/todo.html" />tars all files in the htdocs/manual directory into a file called manual.tar in the ${dist} directory. Files in the directory mydocs, or files with the name todo.html are excluded.
<tar destfile="${basedir}/docs.tar"> <tarfileset dir="${dir.src}/docs" fullpath="/usr/doc/ant/README" preserveLeadingSlashes="true"> <include name="readme.txt"/> </tarfileset> <tarfileset dir="${dir.src}/docs" prefix="/usr/doc/ant" preserveLeadingSlashes="true"> <include name="*.html"/> </tarfileset> </tar>Writes the file docs/readme.txt as /usr/doc/ant/README into the archive. All *.html files in the docs directory are prefixed by /usr/doc/ant, so for example docs/index.html is written as /usr/doc/ant/index.html to the archive.
<tar longfile="gnu" destfile="${dist.base}/${dist.name}-src.tar" > <tarfileset dir="${dist.name}/.." mode="755" username="ant" group="ant"> <include name="${dist.name}/bootstrap.sh"/> <include name="${dist.name}/build.sh"/> </tarfileset> <tarfileset dir="${dist.name}/.." username="ant" group="ant"> <include name="${dist.name}/**"/> <exclude name="${dist.name}/bootstrap.sh"/> <exclude name="${dist.name}/build.sh"/> </tarfileset> </tar>This example shows building a tar which uses the GNU extensions for long paths and where some files need to be marked as executable (mode 755) and the rest are use the default mode (read-write by owner). The first fileset selects just the executable files. The second fileset must exclude the executable files and include all others.
Note: The tar task does not ensure that a file is only selected by one fileset. If the same file is selected by more than one fileset, it will be included in the tar file twice, with the same path.
Note: The patterns in the include and exclude elements are considered to be relative to the corresponding dir attribute as with all other filesets. In the example above, ${dist.name} is not an absolute path, but a simple name of a directory, so ${dist.name} is a valid path relative to ${dist.name}/...