source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/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: 13.7 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<h3>Parameters</h3>
59<table border="1" cellpadding="2" cellspacing="0">
60 <tr>
61 <td valign="top"><b>Attribute</b></td>
62 <td valign="top"><b>Description</b></td>
63 <td align="center" valign="top"><b>Required</b></td>
64 </tr>
65 <tr>
66 <td valign="top">destfile</td>
67 <td valign="top">the JAR file to create.</td>
68 <td valign="top" align="center">Yes</td>
69 </tr>
70 <tr>
71 <td valign="top">basedir</td>
72 <td valign="top">the directory from which to jar the files.</td>
73 <td valign="top" align="center">No</td>
74 </tr>
75 <tr>
76 <td valign="top">compress</td>
77 <td valign="top">Not only store data but also compress them,
78 defaults to true. Unless you set the <em>keepcompression</em>
79 attribute to false, this will apply to the entire archive, not
80 only the files you've added while updating.</td>
81 <td align="center" valign="top">No</td>
82 </tr>
83 <tr>
84 <td valign="top">keepcompression</td>
85 <td valign="top">For entries coming from existing archives (like
86 nested <em>zipfileset</em>s or while updating the archive), keep
87 the compression as it has been originally instead of using the
88 <em>compress</em> attribute. Defaults false. <em>Since Ant
89 1.6</em></td>
90 <td align="center" valign="top">No</td>
91 </tr>
92 <tr>
93 <td valign="top">encoding</td>
94 <td valign="top">The character encoding to use for filenames
95 inside the archive. Defaults to UTF8. <strong>It is not
96 recommended to change this value as the created archive will most
97 likely be unreadable for Java otherwise.</strong></td>
98 <td align="center" valign="top">No</td>
99 </tr>
100 <tr>
101 <td valign="top">filesonly</td>
102 <td valign="top">Store only file entries, defaults to false</td>
103 <td align="center" valign="top">No</td>
104 </tr>
105 <tr>
106 <td valign="top">includes</td>
107 <td valign="top">comma- or space-separated list of patterns of files that must be
108 included. All files are included when omitted.</td>
109 <td valign="top" align="center">No</td>
110 </tr>
111 <tr>
112 <td valign="top">includesfile</td>
113 <td valign="top">the name of a file. Each line of this file is
114 taken to be an include pattern</td>
115 <td valign="top" align="center">No</td>
116 </tr>
117 <tr>
118 <td valign="top">excludes</td>
119 <td valign="top">comma- or space-separated list of patterns of files that must be
120 excluded. No files (except default excludes) are excluded when omitted.</td>
121 <td valign="top" align="center">No</td>
122 </tr>
123 <tr>
124 <td valign="top">excludesfile</td>
125 <td valign="top">the name of a file. Each line of this file is
126 taken to be an exclude pattern</td>
127 <td valign="top" align="center">No</td>
128 </tr>
129 <tr>
130 <td valign="top">defaultexcludes</td>
131 <td valign="top">indicates whether default excludes should be used or not
132 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
133 <td valign="top" align="center">No</td>
134 </tr>
135 <tr>
136 <td valign="top">manifest</td>
137 <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>
138 <td valign="top" align="center">No</td>
139 </tr>
140 <tr>
141 <td valign="top">filesetmanifest</td>
142 <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;.
143 </td>
144 <td valign="top" align="center">No</td>
145 </tr>
146 <tr>
147 <td valign="top">update</td>
148 <td valign="top">indicates whether to update or overwrite
149 the destination file if it already exists. Default is &quot;false&quot;.</td>
150 <td valign="top" align="center">No</td>
151 </tr>
152 <tr>
153 <td valign="top">whenempty</td>
154 <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>
155 <td valign="top" align="center">No</td>
156 </tr>
157 <tr>
158 <td valign="top">duplicate</td>
159 <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>
160 <td valign="top" align="center">No</td>
161 </tr>
162 <tr>
163 <td valign="top">index</td>
164 <td valign="top">whether to create an <A
165 HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index
166 list</A> to speed up classloading. This is a JDK 1.3+ specific
167 feature. Unless you specify additional jars with nested <a
168 href="#indexjars"><code>indexjars</code></a> elements, only the
169 contents of this jar will be included in the index. Defaults to
170 false.</td>
171 <td valign="top" align="center">No</td>
172 </tr>
173 <tr>
174 <td valign="top">manifestencoding</td>
175 <td valign="top">The encoding used to read the JAR manifest, when a manifest file is specified.</td>
176 <td valign="top" align="center">No, defaults to the platform encoding.</td>
177 </tr>
178 <tr>
179 <td valign="top">roundup</td>
180 <td valign="top">Whether the file modification times will be
181 rounded up to the next even number of seconds.<br>
182 Zip archives store file modification times with a granularity of
183 two seconds, so the times will either be rounded up or down. If
184 you round down, the archive will always seem out-of-date when you
185 rerun the task, so the default is to round up. Rounding up may
186 lead to a different type of problems like JSPs inside a web
187 archive that seem to be slightly more recent than precompiled
188 pages, rendering precompilation useless.<br>
189 Defaults to true. <em>Since Ant 1.6.2</em></td>
190 <td align="center" valign="top">No</td>
191 </tr>
192</table>
193
194<h3>Nested elements</h3>
195<h4>metainf</h4>
196<p>The nested <code>metainf</code> element specifies a <a
197href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
198end up in the <code>META-INF</code> directory of the jar file. If this
199fileset includes a file named <code>MANIFEST.MF</code>, the file is
200ignored and you will get a warning.</p>
201
202<h4>manifest</h4>
203<p>The manifest nested element allows the manifest for the Jar file to
204be provided inline in the build file rather than in an external
205file. This element is identical to the
206<a href="manifest.html">manifest</a> task, but the file and mode
207attributes must be omitted.</p>
208<p>
209If both an inline manifest and an external file are both specified, the
210manifests are merged.
211</p>
212
213<p>When using inline manifests, the Jar task will check whether the manifest
214contents have changed (i.e. the manifest as specified is different in any way
215from the manifest that exists in the Jar, if it exists.
216If the manifest values have changed the jar will be updated or rebuilt, as
217appropriate.
218</p>
219
220<a name="indexjars"></a><h4>indexjars</h4>
221
222<p><em>since ant 1.6.2</em></p>
223
224<p>The nested <code>indexjars</code> element specifies a <a
225href="../using.html#path">PATH like structure</a>. Its content is
226completely ignored unless you set the index attribute of the task to
227true.</p>
228
229<p>The index created by this task will contain indices for the
230archives contained in this path, the names used for the archioves
231depend on your manifest:</p>
232<ul>
233 <li>If the generated jar's manifest contains no Class-Path
234 attribute, the file name without any leading directory path will be
235 used and all parts of the path will get indexed.</li>
236 <li>If the manifest contains a Class-Path attribute, this task will
237 try to guess which part of the Class-Path belongs to a given
238 archive. If it cannot guess a name, the archive will be skipped,
239 otherwise tha name listed inside the Class-PAth attribute will be
240 used.</li>
241</ul>
242
243<p>This task will not create any index entries for archives that are
244empty or only contain files inside the META-INF directory.</p>
245
246<h3>Examples</h3>
247<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot; basedir=&quot;${build}/classes&quot;/&gt;</pre>
248<p>jars all files in the <code>${build}/classes</code> directory into a file
249called <code>app.jar</code> in the <code>${dist}/lib</code> directory.</p>
250<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;
251 basedir=&quot;${build}/classes&quot;
252 excludes=&quot;**/Test.class&quot;
253 /&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. Files
256with the name <code>Test.class</code> are excluded.</p>
257<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;
258 basedir=&quot;${build}/classes&quot;
259 includes=&quot;mypackage/test/**&quot;
260 excludes=&quot;**/Test.class&quot;
261 /&gt;</pre>
262<p>jars all files in the <code>${build}/classes</code> directory into a file
263called <code>app.jar</code> in the <code>${dist}/lib</code> directory. Only
264files under the directory <code>mypackage/test</code> are used, and files with
265the name <code>Test.class</code> are excluded.</p>
266<pre> &lt;jar destfile=&quot;${dist}/lib/app.jar&quot;&gt;
267 &lt;fileset dir=&quot;${build}/classes&quot;
268 excludes=&quot;**/Test.class&quot;
269 /&gt;
270 &lt;fileset dir=&quot;${src}/resources&quot;/&gt;
271 &lt;/jar&gt;</pre>
272<p>jars all files in the <code>${build}/classes</code> directory and also
273in the <code>${src}/resources</code> directory together into a file
274called <code>app.jar</code> in the <code>${dist}/lib</code> directory.
275Files with the name <code>Test.class</code> are excluded.
276If there are files such as <code>${build}/classes/mypackage/MyClass.class</code>
277and <code>${src}/resources/mypackage/image.gif</code>, they will appear
278in the same directory in the JAR (and thus be considered in the same package
279by Java).</p>
280
281<pre> &lt;jar destfile=&quot;test.jar&quot; basedir=&quot;.&quot;&gt;
282 &lt;include name=&quot;build&quot;/&gt;
283 &lt;manifest&gt;
284 &lt;attribute name=&quot;Built-By&quot; value=&quot;${user.name}&quot;/&gt;
285 &lt;section name=&quot;common/class1.class&quot;&gt;
286 &lt;attribute name=&quot;Sealed&quot; value=&quot;false&quot;/&gt;
287 &lt;/section&gt;
288 &lt;/manifest&gt;
289 &lt;/jar&gt;</pre>
290<p>
291This is an example of an inline manifest specification. Note that the Built-By
292attribute will take the value of the Ant property ${user.name}. The manifest
293produced by the above would look like this:
294</p>
295<pre><code>Manifest-Version: 1.0
296Built-By: conor
297Created-By: Apache Ant 1.5alpha
298
299Name: common/class1.class
300Sealed: false</code></pre>
301
302<hr>
303<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
304Reserved.</p>
305
306</body>
307</html>
308
Note: See TracBrowser for help on using the repository browser.