You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tar.html 8.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="tar">Tar</a></h2>
  8. <h3>Description</h3>
  9. <p>Creates a tar archive.</p>
  10. <p>The <i>basedir</i> attribute is the reference directory from where to tar.</p>
  11. <p>This task is a <a href="../dirtasks.html#directorybasedtasks">directory based task</a>
  12. and, as such, forms an implicit <a href="../CoreTypes/fileset.html">Fileset</a>. This
  13. defines which files, relative to the <i>basedir</i>, will be included in the
  14. archive. The tar task supports all the attributes of Fileset to refine the
  15. set of files to be included in the implicit fileset.</p>
  16. <p>In addition to the implicit fileset, the tar task supports nested filesets. These
  17. filesets are extended to allow control over the access mode, username and groupname
  18. to be applied to the tar entries. This is useful, for example, when preparing archives for
  19. Unix systems where some files need to have execute permission.</p>
  20. <p>Early versions of tar did not support path lengths greater than 100
  21. characters. Modern versions of tar do so, but in incompatible ways.
  22. The behaviour of the tar task when it encounters such paths is
  23. controlled by the <i>longfile</i> attribute.
  24. If the longfile attribute is set to <code>fail</code>, any long paths will
  25. cause the tar task to fail. If the longfile attribute is set to
  26. <code>truncate</code>, any long paths will be truncated to the 100 character
  27. maximum length prior to adding to the archive. If the value of the longfile
  28. attribute is set to <code>omit</code> then files containing long paths will be
  29. omitted from the archive. Either option ensures that the archive can be
  30. untarred by any compliant version of tar. If the loss of path or file
  31. information is not acceptable, and it rarely is, longfile may be set to the
  32. value <code>gnu</code>. The tar task will then produce a GNU tar file which
  33. can have arbitrary length paths. Note however, that the resulting archive will
  34. only be able to be untarred with GNU tar. The default for the longfile
  35. attribute is <code>warn</code> which behaves just like the gnu option except
  36. that it produces a warning for each file path encountered that does not match
  37. the limit.</p>
  38. <p>Note that this task does not perform compression. You might want to use the
  39. <a href="gzip.html">GZip</a> task to prepare a .tar.gz package.</p>
  40. <h3>Parameters</h3>
  41. <table border="1" cellpadding="2" cellspacing="0">
  42. <tr>
  43. <td valign="top"><b>Attribute</b></td>
  44. <td valign="top"><b>Description</b></td>
  45. <td valign="top" align="center"><b>Required</b></td>
  46. </tr>
  47. <tr>
  48. <td valign="top">tarfile</td>
  49. <td valign="top">the tar-file to create.</td>
  50. <td align="center" valign="top">Yes</td>
  51. </tr>
  52. <tr>
  53. <td valign="top">basedir</td>
  54. <td valign="top">the directory from which to zip the files.</td>
  55. <td align="center" valign="top">No</td>
  56. </tr>
  57. <tr>
  58. <td valign="top">longfile</td>
  59. <td valign="top">Determines how long files (&gt;100 chars) are to be
  60. handled. Allowable values are &quot;truncate&quot;, &quot;fail&quot;,
  61. &quot;warn&quot;, &quot;omit&quot; and &quot;gnu&quot;. Default is
  62. &quot;warn&quot;.</td>
  63. <td valign="top" align="center">No</td>
  64. </tr>
  65. <tr>
  66. <td valign="top">includes</td>
  67. <td valign="top">comma separated list of patterns of files that must be
  68. included. All files are included when omitted.</td>
  69. <td valign="top" align="center">No</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">includesfile</td>
  73. <td valign="top">the name of a file. Each line of this file is
  74. taken to be an include pattern</td>
  75. <td valign="top" align="center">No</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">excludes</td>
  79. <td valign="top">comma separated list of patterns of files that must be
  80. excluded. No files (except default excludes) are excluded when omitted.</td>
  81. <td valign="top" align="center">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">excludesfile</td>
  85. <td valign="top">the name of a file. Each line of this file is
  86. taken to be an exclude pattern</td>
  87. <td valign="top" align="center">No</td>
  88. </tr>
  89. <tr>
  90. <td valign="top">defaultexcludes</td>
  91. <td valign="top">indicates whether default excludes should be used or not
  92. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  93. <td valign="top" align="center">No</td>
  94. </tr>
  95. </table>
  96. <h3>Nested Elements</h3>
  97. The tar task supports nested <a href="../CoreTypes/fileset.html">tarfileset</a> elements. These are
  98. extended Filesets which, in addition to the standard fileset elements, support three additional
  99. attributes
  100. <table border="1" cellpadding="2" cellspacing="0">
  101. <tr>
  102. <td valign="top"><b>Attribute</b></td>
  103. <td valign="top"><b>Description</b></td>
  104. <td valign="top" align="center"><b>Required</b></td>
  105. </tr>
  106. <tr>
  107. <td valign="top">mode</td>
  108. <td valign="top">An 3 digit octal string, specify the user, group and other modes in
  109. the standard Unix fashion</td>
  110. <td align="center" valign="top">No</td>
  111. </tr>
  112. <tr>
  113. <td valign="top">username</td>
  114. <td valign="top">The username for the tar entry. This is not the same as the UID, which is
  115. not currently set by the tar task.</td>
  116. <td align="center" valign="top">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">group</td>
  120. <td valign="top">The groupname for the tar entry. This is not the same as the GID, which is
  121. not currently set by the tar task.</td>
  122. <td align="center" valign="top">No</td>
  123. </tr>
  124. </table>
  125. <h3>Examples</h3>
  126. <pre> &lt;tar tarfile=&quot;${dist}/manual.tar&quot; basedir=&quot;htdocs/manual&quot;/&gt;
  127. &lt;gzip zipfile=&quot;${dist}/manual.tar.gz&quot; src=&quot;${dist}/manual.tar&quot;/&gt;</pre>
  128. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  129. in the <code>${dist}</code> directory, then applies the gzip task to compress
  130. it.</p>
  131. <pre> &lt;tar tarfile=&quot;${dist}/manual.tar&quot;
  132. basedir=&quot;htdocs/manual&quot;
  133. excludes=&quot;mydocs/**, **/todo.html&quot;
  134. /&gt;</pre>
  135. <p>tars all files in the <code>htdocs/manual</code> directory into a file called <code>manual.tar</code>
  136. in the <code>${dist}</code> directory. Files in the directory <code>mydocs</code>,
  137. or files with the name <code>todo.html</code> are excluded.</p>
  138. <pre>&lt;tar longfile=&quot;gnu&quot;
  139. tarfile=&quot;${dist.base}/${dist.name}-src.tar&quot; &gt;
  140. &lt;tarfileset dir=&quot;${dist.name}/..&quot; mode=&quot;755&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  141. &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  142. &lt;include name=&quot;${dist.name}/build.sh&quot;/&gt;
  143. &lt;/tarfileset&gt;
  144. &lt;tarfileset dir=&quot;${dist.name}/..&quot; username=&quot;ant&quot; group=&quot;ant&quot;&gt;
  145. &lt;include name=&quot;${dist.name}/**&quot;/&gt;
  146. &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
  147. &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
  148. &lt;/tarfileset&gt;
  149. &lt;/tar&gt; </pre>
  150. <p>This example shows building a tar which uses the GNU extensions for long paths and
  151. where some files need to be marked as executable (mode 755)
  152. and the rest are use the default mode (read-write by owner). The first
  153. fileset selects just the executable files. The second fileset must exclude
  154. the executable files and include all others. </p>
  155. <p><strong>Note: </strong> The tar task does not ensure that a file is only selected
  156. by one fileset. If the same file is selected by more than one fileset, it will be included in the
  157. tar file twice, with the same path.</p>
  158. <p><strong>Note:</strong> The patterns in the include and exclude
  159. elements are considered to be relative to the corresponding dir
  160. attribute as with all other filesets. In the example above,
  161. <code>${dist.name}</code> is not an absolute path, but a simple name
  162. of a directory, so <code>${dist.name}</code> is a valid path relative
  163. to <code>${dist.name}/..</code>.</p>
  164. <hr>
  165. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  166. Reserved.</p>
  167. </body>
  168. </html>