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 14 KiB

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