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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Zip Task</title>
  20. </head>
  21. <body>
  22. <h2 id="zip">Zip</h2>
  23. <h3>Description</h3>
  24. <p>Creates a zipfile.</p>
  25. <p>The <var>basedir</var> attribute is the reference directory from where to zip.</p>
  26. <p>Note that file permissions will not be stored in the resulting zipfile.</p>
  27. <p>It is possible to refine the set of files that are being zipped. This can be done with
  28. the <var>includes</var>, <var>includesfile</var>, <var>excludes</var>, <var>excludesfile</var>
  29. and <var>defaultexcludes</var> attributes. With the <var>includes</var> or <var>includesfile</var>
  30. attribute you specify the files you want to have included by using patterns. The <var>exclude</var>
  31. or <var>excludesfile</var> attribute is used to specify the files you want to have excluded. This is
  32. also done with patterns. And finally with the <var>defaultexcludes</var> attribute, you can specify
  33. whether you want to use default exclusions or not. See the section
  34. on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  35. inclusion/exclusion of files works, and how to write patterns.</p>
  36. <p>This task forms an implicit <a href="../Types/fileset.html">FileSet</a> and supports most
  37. attributes of <code>&lt;fileset&gt;</code> (<var>dir</var> becomes <var>basedir</var>) as well as
  38. the nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>
  39. and <code>&lt;patternset&gt;</code> elements.</p>
  40. <p>Or, you may place within it nested file sets, or references to file sets. In this
  41. case <var>basedir</var> is optional; the implicit file set is <em>only used</em>
  42. if <var>basedir</var> is set. You may use any mixture of the implicit file set
  43. (with <var>basedir</var> set, and optional attributes like <var>includes</var> and optional
  44. subelements like <code>&lt;include&gt;</code>); explicit nested <code>&lt;fileset&gt;</code>
  45. elements so long as at least one fileset total is specified. The ZIP file will only reflect the
  46. relative paths of files <em>within</em> each fileset. The Zip task and its derivatives know a
  47. special form of a fileset named <code>zipfileset</code> that has additional attributes (described
  48. below).</p>
  49. <p>The Zip task also supports the merging of multiple zip files into the zip file. This is possible
  50. through either the <var>src</var> attribute of any nested filesets or by using the special nested
  51. fileset <code>zipgroupfileset</code>.</p>
  52. <p>The <var>update</var> parameter controls what happens if the ZIP file already exists. When set
  53. to <q>yes</q>, the ZIP file is updated with the files specified. (New files are added; old files are
  54. replaced with the new versions.) When set to <q>no</q> (the default) the ZIP file is overwritten if
  55. any of the files that would be added to the archive are newer than the entries inside the archive.
  56. Please note that ZIP files store file modification times with a granularity of 2 seconds. If a file
  57. is less than 2 seconds newer than the entry in the archive, Apache Ant will not consider it
  58. newer.</p>
  59. <p>The <var>whenempty</var> parameter controls what happens when no files match. If <q>skip</q>
  60. (the default), the ZIP is not created and a warning is issued. If <q>fail</q>, the ZIP is not
  61. created and the build is halted with an error. If <q>create</q>, an empty ZIP file (explicitly zero
  62. entries) is created, which should be recognized as such by compliant ZIP manipulation tools.</p>
  63. <p>This task will now use default JVM character encoding for filenames&mdash;this is consistent with
  64. the command line ZIP tools, but causes problems if you try to open them from within Java and your
  65. filenames contain non US-ASCII characters. Use the <var>encoding</var> attribute and set it
  66. to <q>UTF8</q> to create zip files that can safely be read by Java. For a more complete discussion,
  67. see <a href="#encoding">below</a></p>
  68. <p><em>Since Ant 1.5.2</em>, <code>&lt;zip&gt;</code> can store Unix permissions inside the archive
  69. (see description of the <var>filemode</var> and <var>dirmode</var> attributes
  70. for <a href="../Types/zipfileset.html">&lt;zipfileset&gt;</a>). Unfortunately there is no portable
  71. way to store these permissions. Ant uses the algorithm used by <a href="http://www.info-zip.org"
  72. target="_top">Info-Zip's</a> implementation of the <kbd>zip</kbd> and <kbd>unzip</kbd>
  73. commands&mdash;these are the default versions of <kbd>zip</kbd> and <kbd>unzip</kbd> for many
  74. Unix(-like) systems.</p>
  75. <p><strong>Please note that the zip format allows multiple files of the same fully-qualified name to
  76. exist within a single archive. This has been documented as causing various problems for
  77. unsuspecting users. If you wish to avoid this behavior you must set the <var>duplicate</var>
  78. attribute to a value other than its default, <q>add</q>.</strong></p>
  79. <p><strong>Please also note</strong> that different ZIP tools handle timestamps differently when it
  80. comes to applying timezone offset calculations of files. Some ZIP libraries will store the
  81. timestamps as they've been read from the filesystem while others will modify the timestamps both
  82. when reading and writing the files to make all timestamps use the same timezone. A ZIP archive
  83. created by one library may extract files with "wrong timestamps" when extracted by another
  84. library.</p>
  85. <p>Ant's ZIP classes use the same algorithm as the InfoZIP tools and zlib (timestamps get adjusted),
  86. Windows' "compressed folders" function and WinZIP don't change the timestamps. This means that
  87. using the <code>unzip</code> task on files created by Windows' compressed folders function may
  88. create files with timestamps that are "wrong", the same is true if you use Windows' functions to
  89. extract an Ant generated ZIP archive.</p>
  90. <h3>Parameters</h3>
  91. <table class="attr">
  92. <tr>
  93. <th scope="col">Attribute</th>
  94. <th scope="col">Description</th>
  95. <th scope="col">Required</th>
  96. </tr>
  97. <tr>
  98. <td>destfile</td>
  99. <td>the zip file to create.</td>
  100. <td rowspan="2">Exactly one of the two</td>
  101. </tr>
  102. <tr>
  103. <td>zipfile</td>
  104. <td class="left"><em><u>deprecated</u></em> old name of <var>destfile</var>.</td>
  105. </tr>
  106. <tr>
  107. <td>basedir</td>
  108. <td>the directory from which to zip the files.</td>
  109. <td>No</td>
  110. </tr>
  111. <tr>
  112. <td>compress</td>
  113. <td>Not only store data but also compress them. Unless you set the <var>keepcompression</var>
  114. attribute to <q>false</q>, this will apply to the entire archive, not only the files you've
  115. added while updating.</td>
  116. <td>No; defaults to <q>true</q></td>
  117. </tr>
  118. <tr>
  119. <td>keepcompression</td>
  120. <td>For entries coming from existing archives (like nested <code>zipfileset</code>s or while
  121. updating the archive), keep the compression as it has been originally instead of using
  122. the <var>compress</var> attribute. <em>Since Ant 1.6</em></td>
  123. <td>No; defaults to <q>false</q></td>
  124. </tr>
  125. <tr>
  126. <td>encoding</td>
  127. <td>The character encoding to use for filenames inside the zip file. For a list of possible
  128. values see
  129. the <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html"
  130. target="_top">Supported Encodings</a>.</td>
  131. <td>No; defaults to default JVM character encoding</td>
  132. </tr>
  133. <tr>
  134. <td>filesonly</td>
  135. <td>Store only file entries.</td>
  136. <td>No; defaults to <q>false</q></td>
  137. </tr>
  138. <tr>
  139. <td>includes</td>
  140. <td>comma- or space-separated list of patterns of files that must be included.</td>
  141. <td>No; defaults to all (<q>**</q>)</td>
  142. </tr>
  143. <tr>
  144. <td>includesfile</td>
  145. <td>name of a file. Each line of this file is taken to be an include pattern.</td>
  146. <td>No</td>
  147. </tr>
  148. <tr>
  149. <td>excludes</td>
  150. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  151. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  152. </tr>
  153. <tr>
  154. <td>excludesfile</td>
  155. <td>name of a file. Each line of this file is taken to be an exclude pattern.</td>
  156. <td>No</td>
  157. </tr>
  158. <tr>
  159. <td>defaultexcludes</td>
  160. <td>indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  161. <td>No; defaults to <q>yes</q></td>
  162. </tr>
  163. <tr>
  164. <td>update</td>
  165. <td>indicates whether to update or overwrite the destination file if it already exists.</td>
  166. <td>No; default is <q>false</q></td>
  167. </tr>
  168. <tr>
  169. <td>whenempty</td>
  170. <td>behavior when no files match. Valid values are <q>fail</q>, <q>skip</q>,
  171. and <q>create</q>.</td>
  172. <td>No; default is <q>skip</q></td>
  173. </tr>
  174. <tr>
  175. <td>duplicate</td>
  176. <td>behavior when a duplicate file is found. Valid values are <q>add</q>, <q>preserve</q>,
  177. and <q>fail</q>.</td>
  178. <td>No; default is <q>add</q></td>
  179. </tr>
  180. <tr>
  181. <td>roundup</td>
  182. <td>Whether the file modification times will be rounded up to the next even number of
  183. seconds.<br/>Zip archives store file modification times with a granularity of 2 seconds, so
  184. the times will either be rounded up or down. If you round down, the archive will always seem
  185. out-of-date when you rerun the task, so the default is to round up. Rounding up may lead to a
  186. different type of problems like JSPs inside a web archive that seem to be slightly more recent
  187. than precompiled pages, rendering precompilation useless. <em>Since Ant 1.6.2</em></td>
  188. <td>No; defaults to <q>true</q></td>
  189. </tr>
  190. <tr>
  191. <td>comment</td>
  192. <td>Comment to store in the archive. <em>Since Ant 1.6.3</em></td>
  193. <td>No</td>
  194. </tr>
  195. <tr>
  196. <td>level</td>
  197. <td>Non-default level at which file compression should be performed. Valid values range
  198. from <q>0</q> (no compression/fastest) to <q>9</q> (maximum compression/slowest). <em>Since
  199. Ant 1.7</em></td>
  200. <td>No</td>
  201. </tr>
  202. <tr>
  203. <td>preserve0permissions</td>
  204. <td>when updating an archive or adding entries from a different archive Ant will assume that a
  205. Unix permissions value of 0 (nobody is allowed to do anything to the file/directory) means
  206. that the permissions haven't been stored at all rather than real permissions and will instead
  207. apply its own default values.<br/> Set this attribute to <q>true</q> if you really want to
  208. preserve the original permission field. <em>Since Ant 1.8.0</em>
  209. </td>
  210. <td>No; default is <q>false</q></td>
  211. </tr>
  212. <tr>
  213. <td>useLanguageEncodingFlag</td>
  214. <td>Whether to set the language encoding flag if the encoding is UTF-8. This setting doesn't
  215. have any effect if the encoding is not UTF-8. <em>Since Ant 1.8.0</em>.<br/>See also
  216. the <a href="#encoding">discussion below</a></td>
  217. <td>No; default is <q>true</q></td>
  218. </tr>
  219. <tr>
  220. <td>createUnicodeExtraFields</td>
  221. <td>Whether to create Unicode extra fields to store the file names a second time inside the
  222. entry's metadata.<br/>Possible values are <q>never</q>, <q>always</q>
  223. and <q>not-encodeable</q> which will only add Unicode extra fields if the file name cannot be
  224. encoded using the specified encoding. <em>Since Ant 1.8.0</em>.<br/>See also
  225. the <a href="#encoding">discussion below</a></td>
  226. <td>No; default is <q>never</q></td>
  227. </tr>
  228. <tr>
  229. <td>fallbacktoUTF8</td>
  230. <td>Whether to use UTF-8 and the language encoding flag instead of the specified encoding if a
  231. file name cannot be encoded using the specified encoding. <em>Since Ant 1.8.0</em>.<br/>See
  232. also the <a href="#encoding">discussion below</a></td>
  233. <td>No; default is <q>false</q></td>
  234. </tr>
  235. <tr>
  236. <td>zip64Mode</td>
  237. <td>When to use Zip64 extensions for entries. The possible values
  238. are <q>never</q>, <q>always</q> and <q>as-needed</q>. <em>Since Ant 1.9.1</em>.<br/>See also
  239. the <a href="#zip64">discussion below</a></td>
  240. <td>No; default is <q>as-needed</q></td>
  241. </tr>
  242. <tr>
  243. <td valign="top">modificationtime</td>
  244. <td valign="top">Set all stored file modification times to the
  245. given time. This can either be a number interpreted as
  246. milliseconds since 1970-01-01T00:00:00Z or a string that can be
  247. parsed as a ISO 8601 timestamp with optional timezone.
  248. <em>Since Ant 1.10.2</em>.
  249. </td>
  250. <td align="center" valign="top">No</td>
  251. </tr>
  252. </table>
  253. <h3 id="encoding">Encoding of file names</h3>
  254. <p>Traditionally the ZIP archive format uses CodePage 437 as encoding for file name, which is not
  255. sufficient for many international character sets.</p>
  256. <p>Over time different archivers have chosen different ways to work around the
  257. limitation&mdash;the <code class="code">java.util.zip</code> packages simply uses UTF-8 as its
  258. encoding for example.</p>
  259. <p>Ant has been offering the <q>encoding</q> attribute of the <code>zip</code>
  260. and <code>unzip</code> task as a way to explicitly specify the encoding to use (or expect) <em>since
  261. Ant 1.4</em>. It defaults to default JVM character encoding for <code>zip</code> and UTF-8
  262. for <code>jar</code> and other jar-like tasks (<code>war</code>, <code>ear</code>, ...) as well as
  263. the <code>unzip</code> family of tasks.</p>
  264. <p>More recent versions of the ZIP specification introduce something called the <q>language encoding
  265. flag</q> which can be used to signal that a file name has been encoded using UTF-8. <em>Since Ant
  266. 1.8.0</em>, all zip, jar and similar archives written by Ant will set this flag, if the encoding has
  267. been set to UTF-8. Our interoperability tests with existing archivers didn't show any ill effects
  268. (in fact, most archivers ignore the flag to date), but you can turn off the <q>language encoding
  269. flag</q> by setting the attribute <var>useLanguageEncodingFlag</var> to <q>false</q> on
  270. the <code>zip</code> task if you should encounter problems.</p>
  271. <p>The <code>unzip</code> task (and similar tasks) will recognize the language encoding flag and
  272. ignore the encoding set on the task if it has been found.</p>
  273. <p>The InfoZIP developers have introduced new ZIP extra fields that can be used to add an additional
  274. UTF-8 encoded file name to the entry's metadata. Most archivers ignore these extra
  275. fields. <em>Since Ant 1.8.0</em>, the <code>zip</code> family of tasks support an
  276. option <var>createUnicodeExtraFields</var>, which makes Ant write these extra fields either for all
  277. entries (<q>always</q>) or only those whose name cannot be encoded using the specified encoding
  278. (<q>not-encodeable</q>), it defaults to <q>never</q> since the extra fields create bigger
  279. archives.</p>
  280. <p>The <var>fallbackToUTF8</var> attribute of <code>zip</code> can be used to create archives that
  281. use the specified encoding in the majority of cases but UTF-8 and the language encoding flag for
  282. filenames that cannot be encoded using the specified encoding.</p>
  283. <p>The <code>unzip</code> task will recognize the Unicode extra fields by default and read the file
  284. name information from them, unless you set the optional
  285. attribute <var>scanForUnicodeExtraFields</var> to <q>false</q>.</p>
  286. <h4>Recommendations for interoperability</h4>
  287. <p>The optimal setting of flags depends on the archivers you expect as consumers/producers of the
  288. ZIP archives. Below are some test results which may be superseded with later versions of each
  289. tool.</p>
  290. <ul>
  291. <li>The <code class="code">java.util.zip</code> package used by the <kbd>jar</kbd> executable or
  292. to read jars from your <code>CLASSPATH</code> reads and writes UTF-8 names, it doesn't set or
  293. recognize any flags or unicode extra fields.</li>
  294. <li>Since Java 7, <code class="code">java.util.zip</code> writes UTF-8 by default and uses the
  295. language encoding flag. It is possible to specify a different encoding when reading/writing
  296. ZIPs via new constructors. The package now recognizes the language encoding flag when reading
  297. and ignores the Unicode extra fields.</li>
  298. <li>7Zip writes CodePage 437 by default but uses UTF-8 and the language encoding flag when writing
  299. entries that cannot be encoded as CodePage 437 (similar to the <code>zip</code> task
  300. with <var>fallbacktoUTF8</var> set to <q>true</q>). It recognizes the language encoding flag
  301. when reading and ignores the Unicode extra fields.</li>
  302. <li>WinZIP writes CodePage 437 and uses Unicode extra fields by default. It recognizes the
  303. Unicode extra field and the language encoding flag when reading.</li>
  304. <li>Windows' "compressed folder" feature doesn't recognize any flag or extra field and creates
  305. archives using the default platform encoding&mdash;and expects archives to be in that encoding
  306. when reading them.</li>
  307. <li>InfoZIP based tools can recognize and write both, it is a compile time option and depends on
  308. the platform so your mileage may vary.</li>
  309. <li>PKWARE zip tools recognize both and prefer the language encoding flag. They create archives
  310. using CodePage 437 if possible and UTF-8 plus the language encoding flag for file names that
  311. cannot be encoded as CodePage 437.</li>
  312. </ul>
  313. <p>So, what to do?</p>
  314. <p>If you are creating jars, then <code class="code">java.util.zip</code> is your main consumer. We
  315. recommend you set the encoding to UTF-8 and keep the language encoding flag enabled. The flag won't
  316. help or hurt <code class="code">java.util.zip</code> prior to Java 7 but archivers that support it
  317. will show the correct file names.</p>
  318. <p>For maximum interoparability it is probably best to set the encoding to UTF-8, enable the
  319. language encoding flag and create Unicode extra fields when writing ZIPs. Such archives should be
  320. extracted correctly by <code class="code">java.util.zip</code>, 7Zip, WinZIP, PKWARE tools and most
  321. likely InfoZIP tools. They will be unusable with Windows' "compressed folders" feature and bigger
  322. than archives without the Unicode extra fields, though.</p>
  323. <p>If Windows' "compressed folders" is your primary consumer, then your best option is to explicitly
  324. set the encoding to the target platform. You may want to enable creation of Unicode extra fields so
  325. the tools that support them will extract the file names correctly.</p>
  326. <h3 id="zip64">Zip64 extensions</h3>
  327. <p>Zip64 extensions provide a way to create archives bigger than 4 GB or holding more than 65535
  328. entries&mdash;or add individual entries bigger than 4 GB using the ZIP extension field mechanism.
  329. These extensions are supported by most modern ZIP implementations.</p>
  330. <p>When Ant writes compressed entries into the archive it creates it doesn't know the compressed
  331. size of an entry before it has been written. Unfortunately the decision whether a Zip64 extra field
  332. will be written has to be made before writing the entry's content.</p>
  333. <p>Ant 1.9.0 introduced support for Zip64 extensions but didn't provide any control over their
  334. usage. <em>Since Ant 1.9.1</em>, a new <var>zip64mode</var> attribute was added to
  335. the <code>zip</code> family of tasks. It supports three values:
  336. <ul>
  337. <li><q>never</q> means no Zip64 extra fields will ever be written. This is the behavior of Ant
  338. prior to 1.9.0 and the default behavior of <code>jar</code>, <code>ear</code>
  339. and <code>war</code> <em>since Ant 1.9.1</em>.</li>
  340. <li><q>always</q> means Zip64 extra fields are written for all entries.</li>
  341. <li><q>as-needed</q> means Zip64 extra fields are written for all compressed entries to the "local
  342. file header" (by default these are all files but not the directories) but only written to the
  343. central directory if the entry really required Zip64 features. This is the default behavior of
  344. Ant 1.9.0 and remains the default behavior of the <code>zip</code> task.</li>
  345. </ul>
  346. <p><q>as-needed</q> provides a good compromise if you don't know whether you archive will exceed the
  347. limits of traditional zip files but don't want to waste too much space (the Zip64 extensions take up
  348. extra space). Unfortunately some ZIP implementations don't understand Zip64 extra fields or fail to
  349. parse archives with extra fields in local file headers that are not present in the central
  350. directory, one such implementation is the <code class="code">java.util.zip</code> package of Java 5,
  351. that's why the <code>jar</code> tasks default to <q>never</q>. Archives created
  352. with <q>as-needed</q> can be read without problems with Java 6 and later.</p>
  353. <h3>Parameters specified as nested elements</h3>
  354. <h4>any resource collection</h4>
  355. <p><a href="../Types/resources.html#collection">resource collections</a> are used to select groups
  356. of files to archive.</p>
  357. <p>Prior to Ant 1.7 only <code>&lt;fileset&gt;</code> and <code>&lt;zipfileset&gt;</code> have been
  358. supported as nested elements.</p>
  359. <h4 id="zipgroupfileset">zipgroupfileset</h4>
  360. <p>A <code>&lt;zipgroupfileset&gt;</code> allows for multiple zip files to be merged into the
  361. archive. Each file found in this fileset is added to the archive the same way
  362. that <code>zipfileset</code> <var>src</var> files are added.</p>
  363. <p><code>&lt;zipgroupfileset&gt;</code> is a <a href="../Types/fileset.html">fileset</a> and
  364. supports all of its attributes and nested elements.</p>
  365. <h3>Examples</h3>
  366. <p>Zip all files in the <samp>htdocs/manual</samp> directory into a file
  367. called <samp>manual.zip</samp> in the <samp>${dist}</samp> directory.</p>
  368. <pre>
  369. &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  370. basedir=&quot;htdocs/manual&quot;/&gt;</pre>
  371. <p>Zip all files in the <samp>htdocs/manual</samp> directory into a file
  372. called <samp>manual.zip</samp> in the <samp>${dist}</samp> directory. If <samp>manual.zip</samp>
  373. doesn't exist, it is created; otherwise it is updated with the new/changed files.</p>
  374. <pre>
  375. &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  376. basedir=&quot;htdocs/manual&quot;
  377. update=&quot;true&quot;/&gt;</pre>
  378. <p>Zip all files in the <samp>htdocs/manual</samp> directory. Files in the
  379. directory <samp>mydocs</samp>, or files with the name <samp>todo.html</samp> are excluded.</p>
  380. <pre>
  381. &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  382. basedir=&quot;htdocs/manual&quot;
  383. excludes=&quot;mydocs/**, **/todo.html&quot;/&gt;</pre>
  384. <p>Zip all files in the <samp>htdocs/manual</samp> directory. Only <samp>html</samp> files under the
  385. directory <samp>api</samp> are zipped, and files with the name <samp>todo.html</samp> are
  386. excluded.</p>
  387. <pre>
  388. &lt;zip destfile=&quot;${dist}/manual.zip&quot;
  389. basedir=&quot;htdocs/manual&quot;
  390. includes=&quot;api/**/*.html&quot;
  391. excludes=&quot;**/todo.html&quot;/&gt;</pre>
  392. <p>Zip all files in the <samp>htdocs/manual</samp> directory, and also add the
  393. file <samp>ChangeLog.txt</samp> in the current directory. <samp>ChangeLog.txt</samp> will be added
  394. to the top of the ZIP file, just as if it had been located
  395. at <samp>htdocs/manual/ChangeLog.txt</samp>.</p>
  396. <pre>
  397. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  398. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  399. &lt;fileset dir=&quot;.&quot; includes=&quot;ChangeLog.txt&quot;/&gt;
  400. &lt;/zip&gt;</pre>
  401. <p>Zip all files in the <samp>htdocs/manual</samp> directory into the <samp>docs/user-guide</samp>
  402. directory in the archive, adds the file <samp>ChangeLog27.txt</samp> in the current directory
  403. as <samp>docs/ChangeLog.txt</samp>, and includes all the <samp>html</samp> files
  404. in <samp>examples.zip</samp> under <samp>docs/examples</samp>.</p>
  405. <pre>
  406. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  407. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  408. &lt;zipfileset dir=&quot;.&quot; includes=&quot;ChangeLog27.txt&quot; fullpath=&quot;docs/ChangeLog.txt&quot;/&gt;
  409. &lt;zipfileset src=&quot;examples.zip&quot; includes=&quot;**/*.html&quot; prefix=&quot;docs/examples&quot;/&gt;
  410. &lt;/zip&gt;</pre>
  411. <p>The archive might end up containing the files:</p>
  412. <pre>
  413. docs/user-guide/html/index.html
  414. docs/ChangeLog.txt
  415. docs/examples/index.html</pre>
  416. <p>Zip all files in the <samp>htdocs/manual</samp> directory into the <samp>docs/user-guide</samp>
  417. directory in the archive and include all the files in any file that
  418. matches <samp>examples*.zip</samp>, such as all files within <samp>examples1.zip</samp>
  419. or <samp>examples_for_brian.zip</samp>.</p>
  420. <pre>
  421. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  422. &lt;zipfileset dir=&quot;htdocs/manual&quot; prefix=&quot;docs/user-guide&quot;/&gt;
  423. &lt;zipgroupfileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
  424. &lt;/zip&gt;</pre>
  425. <p>The same can be achieved with</p>
  426. <pre>
  427. &lt;zip destfile=&quot;${dist}/manual.zip&quot;&gt;
  428. &lt;mappedresources&gt;
  429. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  430. &lt;globmapper from="*" to="docs/user-guide/*"/&gt;
  431. &lt;/mappedresources&gt;
  432. &lt;archives&gt;
  433. &lt;zips&gt;
  434. &lt;fileset dir=&quot;.&quot; includes=&quot;examples*.zip&quot;/&gt;
  435. &lt;/zips&gt;
  436. &lt;/archives&gt;
  437. &lt;/zip&gt;</pre>
  438. <p>Re-package a TAR archive as a ZIP archive. If Unix file permissions have been stored as part of
  439. the TAR file, they will be retained in the resulting ZIP archive.</p>
  440. <pre>
  441. &lt;zip destfile="release.zip"&gt;
  442. &lt;tarfileset src="release.tar"/&gt;
  443. &lt;/zip&gt;</pre>
  444. </body>
  445. </html>