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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Unzip Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="unzip">Unjar/Untar/Unwar/Unzip</a></h2>
  23. <h3>Description</h3>
  24. <p>Unzips a zip-, war-, or jar file.</p>
  25. <p><a href="../CoreTypes/patternset.html">PatternSet</a>s are used to select files to extract
  26. <I>from</I> the archive. If no patternset is used, all files are extracted.
  27. </p>
  28. <p><a href="../CoreTypes/resources.html#collection">Resource
  29. Collection</a>s may be used to select archived files to perform
  30. unarchival upon. Only file system based resource collections are
  31. supported by Unjar/Unwar/Unzip, this includes <a
  32. href="../CoreTypes/fileset.html">fileset</a>, <a
  33. href="../CoreTypes/filelist.html">filelist</a>, <a
  34. href="../using.html#path">path</a>, and <a
  35. href="../CoreTypes/resources.html#files">files</a>.
  36. Untar supports arbitrary resource collections.
  37. Prior to Ant 1.7 only fileset has been supported as a nested element.</p>
  38. <p>You can define filename transformations by using a nested <a href="../CoreTypes/mapper.html">mapper</a> element. The default mapper is the
  39. <a href="../CoreTypes/mapper.html#identity-mapper">identity mapper</a>.
  40. </p>
  41. <p>File permissions will not be restored on extracted files.</p>
  42. <p>The untar task recognizes the long pathname entries used by GNU tar.<p>
  43. <h3>Parameters</h3>
  44. <table border="1" cellpadding="2" cellspacing="0">
  45. <tr>
  46. <td valign="top"><b>Attribute</b></td>
  47. <td valign="top"><b>Description</b></td>
  48. <td align="center" valign="top"><b>Required</b></td>
  49. </tr>
  50. <tr>
  51. <td valign="top">src</td>
  52. <td valign="top">archive file to expand.</td>
  53. <td align="center" valign="top">Yes, if filesets are not used.</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">dest</td>
  57. <td valign="top">directory where to store the expanded files.</td>
  58. <td align="center" valign="top">Yes</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">overwrite</td>
  62. <td valign="top">Overwrite files, even if they are newer than the
  63. corresponding entries in the archive (true or false, default is
  64. true).</td>
  65. <td align="center" valign="top">No</td>
  66. </tr>
  67. <tr>
  68. <td valign="top">compression</td>
  69. <td valign="top"><b>Note:</b> This attribute is only available for
  70. the <code>untar</code> task.<br>
  71. compression method. Allowable values are &quot;none&quot;,
  72. &quot;gzip&quot; and &quot;bzip2&quot;. Default is
  73. &quot;none&quot;.</td>
  74. <td valign="top" align="center">No</td>
  75. </tr>
  76. <tr>
  77. <td valign="top">encoding</td>
  78. <td valign="top"><b>Note:</b> This attribute is not available for
  79. the <code>untar</code> task.<br>
  80. The character encoding that has been used for filenames
  81. inside the zip file. For a list of possible values see <a
  82. 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>.<br>
  83. Defaults to &quot;UTF8&quot;, use the magic value
  84. <code>native-encoding</code> for the platform's default character
  85. encoding.</td>
  86. <td align="center" valign="top">No</td>
  87. </tr>
  88. </table>
  89. <h3>Examples</h3>
  90. <pre>
  91. &lt;unzip src=&quot;${tomcat_src}/tools-src.zip&quot; dest=&quot;${tools.home}&quot;/&gt;
  92. </pre>
  93. <p>
  94. <pre>
  95. &lt;gunzip src=&quot;tools.tar.gz&quot;/&gt;
  96. &lt;untar src=&quot;tools.tar&quot; dest=&quot;${tools.home}&quot;/&gt;
  97. </pre>
  98. <pre>
  99. &lt;unzip src=&quot;${tomcat_src}/tools-src.zip&quot;
  100. dest=&quot;${tools.home}&quot;&gt;
  101. &lt;patternset&gt;
  102. &lt;include name=&quot;**/*.java&quot;/&gt;
  103. &lt;exclude name=&quot;**/Test*.java&quot;/&gt;
  104. &lt;/patternset&gt;
  105. &lt;/unzip&gt;
  106. </pre>
  107. <p>
  108. <pre>
  109. &lt;unzip dest=&quot;${tools.home}&quot;&gt;
  110. &lt;patternset&gt;
  111. &lt;include name=&quot;**/*.java&quot;/&gt;
  112. &lt;exclude name=&quot;**/Test*.java&quot;/&gt;
  113. &lt;/patternset&gt;
  114. &lt;fileset dir=&quot;.&quot;&gt;
  115. &lt;include name=&quot;**/*.zip&quot;/&gt;
  116. &lt;exclude name=&quot;**/tmp*.zip&quot;/&gt;
  117. &lt;/fileset&gt;
  118. &lt;/unzip&gt;
  119. </pre>
  120. <p>
  121. <pre>
  122. &lt;unzip src=&quot;apache-ant-bin.zip&quot; dest=&quot;${tools.home}&quot;&gt;
  123. &lt;patternset&gt;
  124. &lt;include name=&quot;apache-ant/lib/ant.jar&quot;/&gt;
  125. &lt;/patternset&gt;
  126. &lt;mapper type=&quot;flatten&quot;/&gt;
  127. &lt;/unzip&gt;
  128. </pre>
  129. <h3>Related tasks</h3>
  130. <pre>
  131. &lt;unzip src="some-archive" dest="some-dir"&gt;
  132. &lt;patternset&gt;
  133. &lt;include name="some-pattern"/&gt;
  134. &lt;/patternset&gt;
  135. &lt;mapper type=&quot;some-mapper&quot;/&gt;
  136. &lt;/unzip&gt;
  137. </pre>
  138. is identical to
  139. <pre>
  140. &lt;copy todir="some-dir" preservelastmodified="true"&gt;
  141. &lt;zipfileset src="some-archive"&gt;
  142. &lt;patternset&gt;
  143. &lt;include name="some-pattern"/&gt;
  144. &lt;/patternset&gt;
  145. &lt;/zipfileset&gt;
  146. &lt;mapper type=&quot;some-mapper&quot;/&gt;
  147. &lt;/copy&gt;
  148. </pre>
  149. <p>The same is also true for <code>&lt;untar&gt;</code> and
  150. <code>&lt;tarfileset&gt;</code>. <code>&lt;copy&gt;</code> offers
  151. additional features like <a href="../CoreTypes/filterchain.html">filtering files</a> on the fly,
  152. allowing a file to be mapped to multiple destinations or a
  153. configurable file system timestamp granularity.</p>
  154. <pre>&lt;zip destfile=&quot;new.jar&quot;&gt;
  155. &lt;zipfileset src=&quot;old.jar&quot;&gt;
  156. &lt;exclude name=&quot;do/not/include/this/class&quot;/&gt;
  157. &lt;/zipfileset&gt;
  158. &lt;/zip&gt;
  159. </pre>
  160. <p>&quot;Deletes&quot; files from a zipfile.</p>
  161. </body>
  162. </html>