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.

unzip.html 9.1 KiB

7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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>Unzip Task</title>
  20. </head>
  21. <body>
  22. <h2 id="unzip">Unjar/Untar/Unwar/Unzip</h2>
  23. <h3>Description</h3>
  24. <p>Unzips a zip-, war-, or jar file.</p>
  25. <p><a href="../Types/patternset.html">PatternSet</a>s are used to select files to
  26. extract <em>from</em> the archive. If no patternset is used, all files are extracted.</p>
  27. <p><a href="../Types/resources.html#collection">resource collections</a> may be used to select
  28. archived files to perform unarchival upon. Only file system based resource collections are
  29. supported by <code>Unjar</code>/<code>Unwar</code>/<code>Unzip</code>, this
  30. includes <a href="../Types/fileset.html">fileset</a>, <a href="../Types/filelist.html">filelist</a>, <a href="../using.html#path">path</a>,
  31. and <a href="../Types/resources.html#files">files</a>. <code>Untar</code> supports arbitrary
  32. resource collections. Prior to Apache Ant 1.7 only <code>fileset</code> has been supported as a
  33. nested element.</p>
  34. <p>You can define filename transformations by using a
  35. nested <a href="../Types/mapper.html">mapper</a> element. The default mapper is the
  36. <a href="../Types/mapper.html#identity-mapper">identity mapper</a>.</p>
  37. <p>File permissions will not be restored on extracted files.</p>
  38. <p>The <code>untar</code> task recognizes the long pathname entries used by GNU tar.<p>
  39. <p><strong>Please note</strong> that different ZIP tools handle timestamps differently when it comes
  40. to applying timezone offset calculations of files. Some ZIP libraries will store the timestamps as
  41. they've been read from the filesystem while others will modify the timestamps both when reading and
  42. writing the files to make all timestamps use the same timezone. A ZIP archive created by one
  43. library may extract files with "wrong timestamps" when extracted by another library.</p>
  44. <p>Ant's ZIP classes use the same algorithm as the InfoZIP tools and zlib (timestamps get adjusted),
  45. Windows' "compressed folders" function and WinZIP don't change the timestamps. This means that
  46. using the <code>unzip</code> task on files created by Windows' compressed folders function may
  47. create files with timestamps that are "wrong", the same is true if you use Windows' functions to
  48. extract an Ant generated ZIP archive.</p>
  49. <h3>Parameters</h3>
  50. <table class="attr">
  51. <tr>
  52. <th scope="col">Attribute</th>
  53. <th scope="col">Description</th>
  54. <th scope="col">Required</th>
  55. </tr>
  56. <tr>
  57. <td>src</td>
  58. <td>archive file to expand.</td>
  59. <td>Yes, unless filesets are used</td>
  60. </tr>
  61. <tr>
  62. <td>dest</td>
  63. <td>directory where to store the expanded files.</td>
  64. <td>Yes</td>
  65. </tr>
  66. <tr>
  67. <td>overwrite</td>
  68. <td>Overwrite files, even if they are newer than the corresponding entries in the archive
  69. (<q>true|false</q>).</td>
  70. <td>No; default is <q>true</q></td>
  71. </tr>
  72. <tr>
  73. <td>compression</td>
  74. <td><strong>Note</strong>: This attribute is only available for the <code>untar</code> task.<br/>
  75. compression method. Allowable values are <q>none</q>, <q>gzip</q>, <q>xz</q>
  76. and <q>bzip2</q>.</td>
  77. <td>No; default is <q>none</q></td>
  78. </tr>
  79. <tr>
  80. <td>encoding</td>
  81. <td>The character encoding that has been used for filenames inside the zip file. For a list of
  82. possible values see
  83. the <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html"
  84. target="_top">Supported Encodings</a>.<br/> Use the magic value <q>native-encoding</q> for
  85. default JVM character encoding.<br/> See also the <a href="zip.html#encoding">discussion in
  86. the zip task page</a></td>
  87. <td>No; defaults to <q>UTF8</q> for <code>unzip</code> and default JVM character encoding
  88. for <code>untar</code> task</td>
  89. </tr>
  90. <tr>
  91. <td>failOnEmptyArchive</td>
  92. <td>whether trying to extract an empty archive is an error. <em>since Ant 1.8.0</em></td>
  93. <td>No; defaults to <q>false</q></td>
  94. </tr>
  95. <tr>
  96. <td>stripAbsolutePathSpec</td>
  97. <td>whether Ant should remove leading <q>/</q> or <q>\</q> characters from the extracted file
  98. name before extracting it. Note that this changes the entry name before
  99. applying <code>include</code>/<code>exclude</code> patterns and before using the nested
  100. mappers (if any). <em>since Ant 1.8.0</em></td>
  101. <td>No; defaults to <q>true</q> <em>since Ant 1.10.4</em>
  102. (used to default to <q>false</q> prior to that)</td>
  103. </tr>
  104. <tr>
  105. <td>scanForUnicodeExtraFields</td>
  106. <td><strong>Note</strong>: This attribute is not available for the <code>untar</code> task.<br/>
  107. If the archive contains Unicode extra fields then use them to set the file names, ignoring the
  108. specified encoding.<br/>See also the <a href="zip.html#encoding">discussion in the zip task
  109. page</a></td>
  110. <td>No; defaults to <q>true</q></td>
  111. </tr>
  112. <tr>
  113. <td>allowFilesToEscapeDest</td>
  114. <td>Whether to allow the extracted file or directory to be outside of the dest
  115. directory. <em>since Ant 1.10.4</em></td>
  116. <td>No, defaults to <q>false</q> unless <var>stripAbsolutePathSpec</var> is <q>false</q> and the
  117. entry's name starts with a leading path spec.</td>
  118. </tr>
  119. </table>
  120. <h3>Examples</h3>
  121. <pre>&lt;unzip src=&quot;${tomcat_src}/tools-src.zip&quot; dest=&quot;${tools.home}&quot;/&gt;</pre>
  122. <pre>
  123. &lt;gunzip src=&quot;tools.tar.gz&quot;/&gt;
  124. &lt;untar src=&quot;tools.tar&quot; dest=&quot;${tools.home}&quot;/&gt;</pre>
  125. <pre>
  126. &lt;unzip src=&quot;${tomcat_src}/tools-src.zip&quot;
  127. dest=&quot;${tools.home}&quot;&gt;
  128. &lt;patternset&gt;
  129. &lt;include name=&quot;**/*.java&quot;/&gt;
  130. &lt;exclude name=&quot;**/Test*.java&quot;/&gt;
  131. &lt;/patternset&gt;
  132. &lt;/unzip&gt;</pre>
  133. <pre>
  134. &lt;unzip dest=&quot;${tools.home}&quot;&gt;
  135. &lt;patternset&gt;
  136. &lt;include name=&quot;**/*.java&quot;/&gt;
  137. &lt;exclude name=&quot;**/Test*.java&quot;/&gt;
  138. &lt;/patternset&gt;
  139. &lt;fileset dir=&quot;.&quot;&gt;
  140. &lt;include name=&quot;**/*.zip&quot;/&gt;
  141. &lt;exclude name=&quot;**/tmp*.zip&quot;/&gt;
  142. &lt;/fileset&gt;
  143. &lt;/unzip&gt;</pre>
  144. <pre>
  145. &lt;unzip src=&quot;apache-ant-bin.zip&quot; dest=&quot;${tools.home}&quot;&gt;
  146. &lt;patternset&gt;
  147. &lt;include name=&quot;apache-ant/lib/ant.jar&quot;/&gt;
  148. &lt;/patternset&gt;
  149. &lt;mapper type=&quot;flatten&quot;/&gt;
  150. &lt;/unzip&gt;</pre>
  151. <p>Extract all images from <samp>ant.jar</samp> which are stored in the <samp>images</samp>
  152. directory of the jar file (or somewhere under it). While extracting the directory structure
  153. (<samp>images</samp>) will be preserved.</p>
  154. <pre>
  155. &lt;unzip src=&quot;${ant.home}/lib/ant.jar&quot; dest=&quot;...&quot;&gt;
  156. &lt;patternset&gt;
  157. &lt;include name=&quot;images/&quot;/&gt;
  158. &lt;/patternset&gt;
  159. &lt;/unzip&gt;</pre>
  160. <p>Extract two files, <samp>ant_logo_large.gif</samp> and <samp>LICENSE.txt</samp>,
  161. from <samp>ant.jar</samp>. More exactly: extract all files with these names from anywhere in the
  162. source file. While extracting the directory structure will be preserved.</p>
  163. <pre>
  164. &lt;unzip src=&quot;${ant.home}/lib/ant.jar&quot; dest=&quot;...&quot;&gt;
  165. &lt;patternset&gt;
  166. &lt;include name=&quot;**/ant_logo_large.gif&quot;/&gt;
  167. &lt;include name=&quot;**/LICENSE.txt&quot;/&gt;
  168. &lt;/patternset&gt;
  169. &lt;/unzip&gt;</pre>
  170. <h3>Related tasks</h3>
  171. <p>The task</p>
  172. <pre>
  173. &lt;unzip src="some-archive" dest="some-dir"&gt;
  174. &lt;patternset&gt;
  175. &lt;include name="some-pattern"/&gt;
  176. &lt;/patternset&gt;
  177. &lt;mapper type=&quot;some-mapper&quot;/&gt;
  178. &lt;/unzip&gt;</pre>
  179. <p>is identical to</p>
  180. <pre>
  181. &lt;copy todir="some-dir" preservelastmodified="true"&gt;
  182. &lt;zipfileset src="some-archive"&gt;
  183. &lt;patternset&gt;
  184. &lt;include name="some-pattern"/&gt;
  185. &lt;/patternset&gt;
  186. &lt;/zipfileset&gt;
  187. &lt;mapper type=&quot;some-mapper&quot;/&gt;
  188. &lt;/copy&gt;</pre>
  189. <p>The same is also true for <code>&lt;untar&gt;</code>
  190. and <code>&lt;tarfileset&gt;</code>. <code>&lt;copy&gt;</code> offers additional features
  191. like <a href="../Types/filterchain.html">filtering files</a> on the fly, allowing a file to be
  192. mapped to multiple destinations or a configurable file system timestamp granularity.</p>
  193. <p>&quot;Delete&quot; files from a zipfile.</p>
  194. <pre>&lt;zip destfile=&quot;new.jar&quot;&gt;
  195. &lt;zipfileset src=&quot;old.jar&quot;&gt;
  196. &lt;exclude name=&quot;do/not/include/this/class&quot;/&gt;
  197. &lt;/zipfileset&gt;
  198. &lt;/zip&gt;</pre>
  199. </body>
  200. </html>