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.

zip.html 13 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Zip Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="zip">Zip</a></h2>
  8. <h3>Description</h3>
  9. <p>Creates a zipfile.</p>
  10. <p>The <i>basedir</i> attribute is the reference directory from where to zip.</p>
  11. <p>Note that file permissions will not be stored in the resulting zipfile.</p>
  12. <p>It is possible to refine the set of files that are being zipped. This can be
  13. done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  14. attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  15. have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  16. the files you want to have excluded. This is also done with patterns. And
  17. finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  18. want to use default exclusions or not. See the section on <a
  19. href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  20. inclusion/exclusion of files works, and how to write patterns. </p>
  21. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  22. supports all attributes of <code>&lt;fileset&gt;</code>
  23. (<code>dir</code> becomes <code>basedir</code>) as well as the nested
  24. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  25. <code>&lt;patternset&gt;</code> elements.</p>
  26. <p>Or, you may place within it nested file sets, or references to file sets.
  27. In this case <code>basedir</code> is optional; the implicit file set is <i>only used</i>
  28. if <code>basedir</code> is set. You may use any mixture of the implicit file set
  29. (with <code>basedir</code> set, and optional attributes like <code>includes</code>
  30. and optional subelements like <code>&lt;include&gt;</code>); explicit nested
  31. <code>&lt;fileset&gt;</code> elements so long as at least one fileset total is specified. The ZIP file will
  32. only reflect the relative paths of files <i>within</i> each fileset. The Zip task and its derivatives know a special form of a fileset named zipfileset that has additional attributes (described below). </p>
  33. <p>The Zip task also supports the merging of multiple zip files into the zip file.
  34. This is possible through either the <i>src</i> attribute of any nested filesets
  35. or by using the special nested fileset <i>zipgroupfileset</i>.</p>
  36. <p>The <code>update</code> parameter controls what happens if the ZIP
  37. file already exists. When set to <code>yes</code>, the ZIP file is
  38. updated with the files specified. (New files are added; old files are
  39. replaced with the new versions.) When set to <code>no</code> (the
  40. default) the ZIP file is overwritten. Please note that ZIP files
  41. store file modification times with a granularity of two seconds. If a
  42. file is less than two seconds newer than the entry in the archive, Ant
  43. will not consider it newer.</p>
  44. <p>The <code>whenempty</code> parameter controls what happens when no files match.
  45. If <code>skip</code> (the default), the ZIP is not created and a warning is issued.
  46. If <code>fail</code>, the ZIP is not created and the build is halted with an error.
  47. If <code>create</code>, an empty ZIP file (explicitly zero entries) is created,
  48. which should be recognized as such by compliant ZIP manipulation tools.</p>
  49. <p>This task will now use the platform's default character encoding
  50. for filenames - this is consistent with the command line ZIP tools,
  51. but causes problems if you try to open them from within Java and your
  52. filenames contain non US-ASCII characters. Use the encoding attribute
  53. and set it to UTF8 to create zip files that can safely be read by
  54. Java.</p>
  55. <p>Starting with Ant 1.6, &lt;zip&gt; can store Unix permissions
  56. inside the archive (see description of the filemode and dirmode
  57. attributes for <a href="#zipfileset">&lt;zipfileset&gt;</a>).
  58. Unfortunately there is no portable way to store these permissions.
  59. Ant uses the algorithm used by <a href="http://www.info-zip.org">Info-Zip's</a>
  60. implementation of the zip and unzip commands - these are the default
  61. versions of zip and unzip for many Unix and Unix-like systems.</p>
  62. <h3>Parameters</h3>
  63. <table border="1" cellpadding="2" cellspacing="0">
  64. <tr>
  65. <td valign="top"><b>Attribute</b></td>
  66. <td valign="top"><b>Description</b></td>
  67. <td valign="top" align="center"><b>Required</b></td>
  68. </tr>
  69. <tr>
  70. <td valign="top">destfile</td>
  71. <td valign="top">the zip-file to create.</td>
  72. <td align="center" valign="top">Yes</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">zipfile</td>
  76. <td valign="top">the <i>deprecated</i> old name of destfile.</td>
  77. <td align="center" valign="top">Yes</td>
  78. </tr>
  79. <tr>
  80. <td valign="top">basedir</td>
  81. <td valign="top">the directory from which to zip the files.</td>
  82. <td align="center" valign="top">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">compress</td>
  86. <td valign="top">Not only store data but also compress them, defaults to true</td>
  87. <td align="center" valign="top">No</td>
  88. </tr>
  89. <tr>
  90. <td valign="top">encoding</td>
  91. <td valign="top">The character encoding to use for filenames
  92. inside the zip file. For a list of possible values see <a
  93. href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html">http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html</a>.
  94. Defaults to the platform's default character encoding.</td>
  95. <td align="center" valign="top">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">filesonly</td>
  99. <td valign="top">Store only file entries, defaults to false</td>
  100. <td align="center" valign="top">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">includes</td>
  104. <td valign="top">comma- or space-separated list of patterns of files that must be
  105. included. All files are included when omitted.</td>
  106. <td valign="top" align="center">No</td>
  107. </tr>
  108. <tr>
  109. <td valign="top">includesfile</td>
  110. <td valign="top">the name of a file. Each line of this file is
  111. taken to be an include pattern</td>
  112. <td valign="top" align="center">No</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">excludes</td>
  116. <td valign="top">comma- or space-separated list of patterns of files that must be
  117. excluded. No files (except default excludes) are excluded when omitted.</td>
  118. <td valign="top" align="center">No</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">excludesfile</td>
  122. <td valign="top">the name of a file. Each line of this file is
  123. taken to be an exclude pattern</td>
  124. <td valign="top" align="center">No</td>
  125. </tr>
  126. <tr>
  127. <td valign="top">defaultexcludes</td>
  128. <td valign="top">indicates whether default excludes should be used or not
  129. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  130. <td valign="top" align="center">No</td>
  131. </tr>
  132. <tr>
  133. <td valign="top">update</td>
  134. <td valign="top">indicates whether to update or overwrite
  135. the destination file if it already exists.</td>
  136. <td valign="top" align="center">No</td>
  137. </tr>
  138. <tr>
  139. <td valign="top">whenempty</td>
  140. <td valign="top">behavior when no files match. Valid values are &quot;fail&quot;, &quot;skip&quot;, and &quot;create&quot;. Default is &quot;skip&quot;.</td>
  141. <td valign="top" align="center">No</td>
  142. </tr>
  143. <tr>
  144. <td valign="top">duplicate</td>
  145. <td valign="top">behavior when a duplicate file is found. Valid values are &quot;add&quot;, &quot;preserve&quot;, and &quot;fail&quot;. The default value is &quot;add&quot;. </td>
  146. <td valign="top" align="center">No</td>
  147. </tr>
  148. </table>
  149. <h3>Parameters specified as nested elements</h3>
  150. <h4>fileset</h4>
  151. <p>The zip task supports any number of nested <a
  152. href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
  153. the files to be included in the archive.</p>
  154. <h4><a name="zipfileset">zipfileset</a></h4>
  155. <p>A <code>&lt;zipfileset&gt;</code> is a special form of a
  156. <code>&lt;fileset&gt;</code> that adds some extra functionality. It
  157. supports all attributes of <code>&lt;fileset&gt;</code> in addition to
  158. those listed below.</p>
  159. <h3>Parameters</h3>
  160. <table border="1" cellpadding="2" cellspacing="0">
  161. <tr>
  162. <td valign="top"><b>Attribute</b></td>
  163. <td valign="top"><b>Description</b></td>
  164. <td valign="top" align="center"><b>Required</b></td>
  165. </tr>
  166. <tr>
  167. <td valign="top">prefix</td>
  168. <td valign="top">all files in the fileset are prefixed with that
  169. path in the archive.</td>
  170. <td align="center" valign="top">No</td>
  171. </tr>
  172. <tr>
  173. <td valign="top">fullpath</td>
  174. <td valign="top">the file described by the fileset is placed at
  175. that exact location in the archive.</td>
  176. <td align="center" valign="top">No</td>
  177. </tr>
  178. <tr>
  179. <td valign="top">src</td>
  180. <td valign="top">may be used in place of the <i>dir</i> attribute
  181. to specify a zip file whose contents will be extracted and
  182. included in the archive.</td>
  183. <td align="center" valign="top">No</td>
  184. </tr>
  185. <tr>
  186. <td valign="top">filemode</td>
  187. <td valign="top">A 3 digit octal string, specify the user, group
  188. and other modes in the standard Unix fashion. Only applies to
  189. plain files. Default is 644. <em>since Ant 1.6</em>.</td>
  190. <td align="center" valign="top">No</td>
  191. </tr>
  192. <tr>
  193. <td valign="top">dirmode</td>
  194. <td valign="top">A 3 digit octal string, specify the user, group
  195. and other modes in the standard Unix fashion. Only applies to
  196. directories. Default is 755. <em>since Ant 1.6</em>.</td>
  197. <td align="center" valign="top">No</td>
  198. </tr>
  199. </table>
  200. <p>The <i>fullpath</i> attribute can only be set for filesets that
  201. represent a single file. The <i>prefix</i> and <i>fullpath</i>
  202. attributes cannot both be set on the same fileset.</p>
  203. <p>When using the <i>src</i> attribute, include and exclude patterns
  204. may be used to specify a subset of the zip file for inclusion in the
  205. archive as with the <i>dir</i> attribute.</p>
  206. <h4>zipgroupfileset</h4>
  207. <p>A <code>&lt;zipgroupfileset&gt;</code> allows for multiple zip files to be
  208. merged into the archive. Each file found in this fileset is added to the archive
  209. the same way that <i>zipfileset src</i> files are added.</p>
  210. <h3>Examples</h3>
  211. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  212. basedir=&quot;htdocs/manual&quot;
  213. /&gt;</pre>
  214. <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
  215. in the <code>${dist}</code> directory.</p>
  216. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  217. basedir=&quot;htdocs/manual&quot;
  218. update=&quot;true&quot;
  219. /&gt;</pre>
  220. <p>zips all files in the <code>htdocs/manual</code> directory into a file called <code>manual.zip</code>
  221. in the <code>${dist}</code> directory. If <code>manual.zip</code>
  222. doesn't exist, it is created; otherwise it is updated with the
  223. new/changed files.</p>
  224. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  225. basedir=&quot;htdocs/manual&quot;
  226. excludes=&quot;mydocs/**, **/todo.html&quot;
  227. /&gt;</pre>
  228. <p>zips all files in the <code>htdocs/manual</code> directory. Files in the directory <code>mydocs</code>,
  229. or files with the name <code>todo.html</code> are excluded.</p>
  230. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  231. basedir=&quot;htdocs/manual&quot;
  232. includes=&quot;api/**/*.html&quot;
  233. excludes=&quot;**/todo.html&quot;
  234. /&gt;</pre>
  235. <p>zips all files in the <code>htdocs/manual</code> directory. Only html files under the directory <code>api</code>
  236. are zipped, and files with the name <code>todo.html</code> are excluded.</p>
  237. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  238. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  239. &lt;fileset dir=&quot;.&quot; includes=&quot;ChangeLog.txt&quot;/&gt;
  240. &lt;/zip&gt;</pre>
  241. <p>zips all files in the <code>htdocs/manual</code> directory, and also adds the file <code>ChangeLog.txt</code> in the
  242. current directory. <code>ChangeLog.txt</code> will be added to the top of the ZIP file, just as if
  243. it had been located at <code>htdocs/manual/ChangeLog.txt</code>.</p>
  244. <pre> &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  245. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  246. &lt;zipfileset dir=&quot;.&quot; includes=&quot;ChangeLog27.txt&quot; fullpath=&quot;docs/ChangeLog.txt&quot;/&gt;
  247. &lt;zipfileset src=&quot;examples.zip&quot; includes=&quot;**/*.html&quot; prefix=&quot;docs/examples&quot;/&gt;
  248. &lt;/zip&gt;</pre>
  249. <p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory
  250. in the archive, adds the file <code>ChangeLog27.txt</code> in the
  251. current directory as <code>docs/ChangeLog.txt</code>, and includes all the html files in <code>examples.zip</code>
  252. under <code>docs/examples</code>. The archive might end up containing the files:</p>
  253. <pre><code> docs/user-guide/html/index.html
  254. docs/ChangeLog.txt
  255. docs/examples/index.html
  256. </code></pre>
  257. <p>
  258. The code
  259. <pre>
  260. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  261. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  262. &lt;zipgroupfileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
  263. &lt;/zip&gt;</pre>
  264. </pre>
  265. <p>
  266. <p>zips all files in the <code>htdocs/manual</code> directory into the <code>docs/user-guide</code> directory in the archive and includes all the files in any file that maches <code>examples*.zip</code>, such as all files within <code>examples1.zip</code> or <code>examples_for_brian.zip</code>.
  267. <hr>
  268. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  269. Reserved.</p>
  270. </body>
  271. </html>