source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/jar.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 14.1 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Jar Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="jar">Jar</a></h2>
12<h3>Description</h3>
13<p>Jars a set of files.</p>
14<p>The <i>basedir</i> attribute is the reference directory from where to jar.</p>
15<p>Note that file permissions will not be stored in the resulting jarfile.</p>
16<p>It is possible to refine the set of files that are being jarred. This can be
17done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
18attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
19have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
20the files you want to have excluded. This is also done with patterns. And
21finally with the <i>defaultexcludes</i> attribute, you can specify whether you
22want to use default exclusions or not. See the section on <a
23href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
24inclusion/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
26supports all attributes of <code>&lt;fileset&gt;</code>
27(<code>dir</code> becomes <code>basedir</code>) as well as the nested
28<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
29<code>&lt;patternset&gt;</code> elements.</p>
30<p>You can also use nested file sets for more flexibility, and specify
31multiple ones to merge together different trees of files into one JAR.
32The extended fileset and groupfileset child elements from the zip task are
33also available in the jar task.
34See the <a href="zip.html">Zip</a> task for more details and examples.</p>
35<p>If the manifest is omitted, a simple one will be supplied by Ant.</p>
36
37<p>The <code>update</code> parameter controls what happens if the JAR
38file already exists. When set to <code>yes</code>, the JAR file is
39updated with the files specified. When set to <code>no</code> (the
40default) the JAR file is overwritten. An example use of this is
41provided in the <a href="zip.html">Zip task documentation</a>. Please
42note that ZIP files store file modification times with a granularity
43of two seconds. If a file is less than two seconds newer than the
44entry in the archive, Ant will not consider it newer.</p>
45
46<p>(The Jar task is a shortcut for specifying the manifest file of a JAR file.
47The same thing can be accomplished by using the <i>fullpath</i>
48attribute of a zipfileset in a Zip task. The one difference is that if the
49<i>manifest</i> attribute is not specified, the Jar task will
50include an empty one for you.)</p>
51
52<p>Manifests are processed by the Jar task according to the
53<a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html">Jar file specification.</a>
54Note in particular that this may result in manifest lines greater than 72 bytes
55being wrapped and continued on the next line.
56</p>
57
58<p><b>Please note that the zip format allows multiple files of the same
59fully-qualified name to exist within a single archive. This has been
60documented as causing various problems for unsuspecting users. If you wish
61to avoid this behavior you must set the <code>duplicate</code> attribute
62to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
63
64<h3>Parameters</h3>
65<table border="1" cellpadding="2" cellspacing="0">
66 <tr>
67 <td valign="top"><b>Attribute</b></td>
68 <td valign="top"><b>Description</b></td>
69 <td align="center" valign="top"><b>Required</b></td>
70 </tr>
71 <tr>
72 <td valign="top">destfile</td>
73 <td valign="top">the JAR file to create.</td>
74 <td valign="top" align="center">Yes</td>
75 </tr>
76 <tr>
77 <td valign="top">basedir</td>
78 <td valign="top">the directory from which to jar the files.</td>
79 <td valign="top" align="center">No</td>
80 </tr>
81 <tr>
82 <td valign="top">compress</td>
83 <td valign="top">Not only store data but also compress them,
84 defaults to true. Unless you set the <em>keepcompression</em>
85 attribute to false, this will apply to the entire archive, not
86 only the files you've added while updating.</td>
87 <td align="center" valign="top">No</td>
88 </tr>
89 <tr>
90 <td valign="top">keepcompression</td>
91 <td valign="top">For entries coming from existing archives (like
92 nested <em>zipfileset</em>s or while updating the archive), keep
93 the compression as it has been originally instead of using the
94 <em>compress</em> attribute. Defaults false. <em>Since Ant
95 1.6</em></td>
96 <td align="center" valign="top">No</td>
97 </tr>
98 <tr>
99 <td valign="top">encoding</td>
100 <td valign="top">The character encoding to use for filenames
101 inside the archive. Defaults to UTF8. <strong>It is not
102 recommended to change this value as the created archive will most
103 likely be unreadable for Java otherwise.</strong></td>
104 <td align="center" valign="top">No</td>
105 </tr>
106 <tr>
107 <td valign="top">filesonly</td>
108 <td valign="top">Store only file entries, defaults to false</td>
109 <td align="center" valign="top">No</td>
110 </tr>
111 <tr>
112 <td valign="top">includes</td>
113 <td valign="top">comma- or space-separated list of patterns of files that must be
114 included. All files are included when omitted.</td>
115 <td valign="top" align="center">No</td>
116 </tr>
117 <tr>
118 <td valign="top">includesfile</td>
119 <td valign="top">the name of a file. Each line of this file is
120 taken to be an include pattern</td>
121 <td valign="top" align="center">No</td>
122 </tr>
123 <tr>
124 <td valign="top">excludes</td>
125 <td valign="top">comma- or space-separated list of patterns of files that must be
126 excluded. No files (except default excludes) are excluded when omitted.</td>
127 <td valign="top" align="center">No</td>
128 </tr>
129 <tr>
130 <td valign="top">excludesfile</td>
131 <td valign="top">the name of a file. Each line of this file is
132 taken to be an exclude pattern</td>
133 <td valign="top" align="center">No</td>
134 </tr>
135 <tr>
136 <td valign="top">defaultexcludes</td>
137 <td valign="top">indicates whether default excludes should be used or not
138 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
139 <td valign="top" align="center">No</td>
140 </tr>
141 <tr>
142 <td valign="top">manifest</td>
143 <td valign="top">the manifest file to use. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF</td>
144 <td valign="top" align="center">No</td>
145 </tr>
146 <tr>
147 <td valign="top">filesetmanifest</td>
148 <td valign="top">behavior when a Manifest is found in a zipfileset or zipgroupfileset file is found. Valid values are &quot;skip&quot;, &quot;merge&quot;, and &quot;mergewithoutmain&quot;. &quot;merge&quot; will merge all of the manifests together, and merge this into any other specified manifests. &quot;mergewithoutmain&quot; merges everything but the Main section of the manifests. Default value is &quot;skip&quot;.
149 </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 &quot;false&quot;.</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 &quot;fail&quot;, &quot;skip&quot;, and &quot;create&quot;. Default is &quot;skip&quot;.</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 &quot;add&quot;, &quot;preserve&quot;, and &quot;fail&quot;. The default value is &quot;add&quot;. </td>
166 <td valign="top" align="center">No</td>
167 </tr>
168 <tr>
169 <td valign="top">index</td>
170 <td valign="top">whether to create an <A
171 HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index
172 list</A> to speed up classloading. This is a JDK 1.3+ specific
173 feature. Unless you specify additional jars with nested <a
174 href="#indexjars"><code>indexjars</code></a> elements, only the
175 contents of this jar will be included in the index. Defaults to
176 false.</td>
177 <td valign="top" align="center">No</td>
178 </tr>
179 <tr>
180 <td valign="top">manifestencoding</td>
181 <td valign="top">The encoding used to read the JAR manifest, when a manifest file is specified.</td>
182 <td valign="top" align="center">No, defaults to the platform encoding.</td>
183 </tr>
184 <tr>
185 <td valign="top">roundup</td>
186 <td valign="top">Whether the file modification times will be
187 rounded up to the next even number of seconds.<br>
188 Zip archives store file modification times with a granularity of
189 two seconds, so the times will either be rounded up or down. If
190 you round down, the archive will always seem out-of-date when you
191 rerun the task, so the default is to round up. Rounding up may
192 lead to a different type of problems like JSPs inside a web
193 archive that seem to be slightly more recent than precompiled
194 pages, rendering precompilation useless.<br>
195 Defaults to true. <em>Since Ant 1.6.2</em></td>
196 <td align="center" valign="top">No</td>
197 </tr>
198</table>
199
200<h3>Nested elements</h3>
201<h4>metainf</h4>
202<p>The nested <code>metainf</code> element specifies a <a
203href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
204end up in the <code>META-INF</code> directory of the jar file. If this
205fileset includes a file named <code>MANIFEST.MF</code>, the file is
206ignored and you will get a warning.</p>
207
208<h4>manifest</h4>
209<p>The manifest nested element allows the manifest for the Jar file to
210be provided inline in the build file rather than in an external
211file. This element is identical to the
212<a href="manifest.html">manifest</a> task, but the file and mode
213attributes must be omitted.</p>
214<p>
215If both an inline manifest and an external file are both specified, the
216manifests are merged.
217</p>
218
219<p>When using inline manifests, the Jar task will check whether the manifest
220contents have changed (i.e. the manifest as specified is different in any way
221from the manifest that exists in the Jar, if it exists.
222If the manifest values have changed the jar will be updated or rebuilt, as
223appropriate.
224</p>
225
226<a name="indexjars"><h4>indexjars</h4></a>
227
228<p><em>since ant 1.6.2</em></p>
229
230<p>The nested <code>indexjars</code> element specifies a <a
231href="../using.html#path">PATH like structure</a>. Its content is
232completely ignored unless you set the index attribute of the task to
233true.</p>
234
235<p>The index created by this task will contain indices for the
236archives contained in this path, the names used for the archioves
237depend on your manifest:</p>
238<ul>
239 <li>If the generated jar's manifest contains no Class-Path
240 attribute, the file name without any leading directory path will be
241 used and all parts of the path will get indexed.</li>
242 <li>If the manifest contains a Class-Path attribute, this task will
243 try to guess which part of the Class-Path belongs to a given
244 archive. If it cannot guess a name, the archive will be skipped,
245 otherwise tha name listed inside the Class-PAth attribute will be
246 used.</li>
247</ul>
248
249<p>This task will not create any index entries for archives that are
250empty or only contain files inside the META-INF directory.</p>
251
252<h3>Examples</h3>
253<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot; basedir=&quot;${build}/classes&quot;/&gt;</pre>
254<p>jars all files in the <code>${build}/classes</code> directory into a file
255called <code>app.jar</code> in the <code>${dist}/lib</code> directory.</p>
256<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;
257 basedir=&quot;${build}/classes&quot;
258 excludes=&quot;**/Test.class&quot;
259 /&gt;</pre>
260<p>jars all files in the <code>${build}/classes</code> directory into a file
261called <code>app.jar</code> in the <code>${dist}/lib</code> directory. Files
262with the name <code>Test.class</code> are excluded.</p>
263<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;
264 basedir=&quot;${build}/classes&quot;
265 includes=&quot;mypackage/test/**&quot;
266 excludes=&quot;**/Test.class&quot;
267 /&gt;</pre>
268<p>jars all files in the <code>${build}/classes</code> directory into a file
269called <code>app.jar</code> in the <code>${dist}/lib</code> directory. Only
270files under the directory <code>mypackage/test</code> are used, and files with
271the name <code>Test.class</code> are excluded.</p>
272<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;&gt;
273 &lt;fileset dir=&quot;${build}/classes&quot;
274 excludes=&quot;**/Test.class&quot;
275 /&gt;
276 &lt;fileset dir=&quot;${src}/resources&quot;/&gt;
277 &lt;/jar&gt;</pre>
278<p>jars all files in the <code>${build}/classes</code> directory and also
279in the <code>${src}/resources</code> directory together into a file
280called <code>app.jar</code> in the <code>${dist}/lib</code> directory.
281Files with the name <code>Test.class</code> are excluded.
282If there are files such as <code>${build}/classes/mypackage/MyClass.class</code>
283and <code>${src}/resources/mypackage/image.gif</code>, they will appear
284in the same directory in the JAR (and thus be considered in the same package
285by Java).</p>
286
287<pre> &lt;jar destfile=&quot;test.jar&quot; basedir=&quot;.&quot;&gt;
288 &lt;include name=&quot;build&quot;/&gt;
289 &lt;manifest&gt;
290 &lt;attribute name=&quot;Built-By&quot; value=&quot;${user.name}&quot;/&gt;
291 &lt;section name=&quot;common/class1.class&quot;&gt;
292 &lt;attribute name=&quot;Sealed&quot; value=&quot;false&quot;/&gt;
293 &lt;/section&gt;
294 &lt;/manifest&gt;
295 &lt;/jar&gt;</pre>
296<p>
297This is an example of an inline manifest specification. Note that the Built-By
298attribute will take the value of the Ant property ${user.name}. The manifest
299produced by the above would look like this:
300</p>
301<pre><code>Manifest-Version: 1.0
302Built-By: conor
303Created-By: Apache Ant 1.5alpha
304
305Name: common/class1.class
306Sealed: false</code></pre>
307
308<hr>
309<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
310Reserved.</p>
311
312</body>
313</html>
314
Note: See TracBrowser for help on using the repository browser.