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