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.

jar.html 8.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="jar">Jar</a></h2>
  8. <h3>Description</h3>
  9. <p>Jars a set of files.</p>
  10. <p>The <i>basedir</i> attribute is the reference directory from where to jar.</p>
  11. <p>Note that file permissions will not be stored in the resulting jarfile.</p>
  12. <p>It is possible to refine the set of files that are being jarred. This can be
  13. done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  14. attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  15. have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  16. the files you want to have excluded. This is also done with patterns. And
  17. finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  18. want to use default exclusions or not. See the section on <a
  19. href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  20. inclusion/exclusion of files works, and how to write patterns.</p>
  21. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  22. supports all attributes of <code>&lt;fileset&gt;</code>
  23. (<code>dir</code> becomes <code>basedir</code>) as well as the nested
  24. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  25. <code>&lt;patternset&gt;</code> elements.</p>
  26. <p>You can also use nested file sets for more flexibility, and specify
  27. multiple ones to merge together different trees of files into one JAR.
  28. The extended fileset attributes from the zip task are also available
  29. in the jar task.
  30. See the <a href="zip.html">Zip</a> task for more details and examples.</p>
  31. <p>If the manifest is omitted, a simple one will be supplied by Ant.
  32. You should not include <samp>META-INF/MANIFEST.MF</samp> in your set of files.</p>
  33. <p>The <code>update</code> parameter controls what happens if the
  34. JAR file already exists. When set to <code>yes</code>, the JAR file is
  35. updated with the files specified. When set to <code>no</code> (the
  36. default) the JAR file is overwritten. An example use of this is
  37. provided in the <a href="zip.html">Zip task documentation</a>.</p>
  38. <p>The <code>whenempty</code> parameter controls what happens when no files match.
  39. If <code>create</code> (the default), the JAR is created anyway with only a manifest.
  40. If <code>skip</code>, the JAR is not created and a warning is issued.
  41. If <code>fail</code>, the JAR is not created and the build is halted with an error.</p>
  42. <p>(The Jar task is a shortcut for specifying the manifest file of a JAR file.
  43. The same thing can be accomplished by using the <i>fullpath</i>
  44. attribute of a zipfileset in a Zip task. The one difference is that if the
  45. <i>manifest</i> attribute is not specified, the Jar task will
  46. include an empty one for you.)</p>
  47. <h3>Parameters</h3>
  48. <table border="1" cellpadding="2" cellspacing="0">
  49. <tr>
  50. <td valign="top"><b>Attribute</b></td>
  51. <td valign="top"><b>Description</b></td>
  52. <td align="center" valign="top"><b>Required</b></td>
  53. </tr>
  54. <tr>
  55. <td valign="top">file</td>
  56. <td valign="top">the jar-file to create.</td>
  57. <td valign="top" align="center">Yes</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">basedir</td>
  61. <td valign="top">the directory from which to jar the files.</td>
  62. <td valign="top" align="center">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">compress</td>
  66. <td valign="top">Not only store data but also compress them, defaults to true</td>
  67. <td align="center" valign="top">No</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">encoding</td>
  71. <td valign="top">The character encoding to use for filenames
  72. inside the archive. Defaults to UTF8. <strong>It is not
  73. recommended to change this value as the created archive will most
  74. likely be unreadable for Java otherwise.</strong></td>
  75. <td align="center" valign="top">No</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">filesonly</td>
  79. <td valign="top">Store only file entries, defaults to false</td>
  80. <td align="center" valign="top">No</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">includes</td>
  84. <td valign="top">comma separated list of patterns of files that must be
  85. included. All files are included when omitted.</td>
  86. <td valign="top" align="center">No</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">includesfile</td>
  90. <td valign="top">the name of a file. Each line of this file is
  91. taken to be an include pattern</td>
  92. <td valign="top" align="center">No</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">excludes</td>
  96. <td valign="top">comma separated list of patterns of files that must be
  97. excluded. No files (except default excludes) are excluded when omitted.</td>
  98. <td valign="top" align="center">No</td>
  99. </tr>
  100. <tr>
  101. <td valign="top">excludesfile</td>
  102. <td valign="top">the name of a file. Each line of this file is
  103. taken to be an exclude pattern</td>
  104. <td valign="top" align="center">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">defaultexcludes</td>
  108. <td valign="top">indicates whether default excludes should be used or not
  109. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  110. <td valign="top" align="center">No</td>
  111. </tr>
  112. <tr>
  113. <td valign="top">manifest</td>
  114. <td valign="top">the manifest file to use.</td>
  115. <td valign="top" align="center">No</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">update</td>
  119. <td valign="top">indicates whether to update or overwrite
  120. the destination file if it already exists.</td>
  121. <td valign="top" align="center">No</td>
  122. </tr>
  123. <tr>
  124. <td valign="top">whenempty</td>
  125. <td valign="top">Behavior to use if no files match.</td>
  126. <td valign="top" align="center">No</td>
  127. </tr>
  128. </table>
  129. <h3>Nested elements</h3>
  130. <h4>metainf</h4>
  131. <p>The nested <code>metainf</code> element specifies a <a
  132. href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
  133. end up in the <code>META-INF</code> directory of the jar file. If this
  134. fileset includes a file named <code>MANIFEST.MF</code>, the file is
  135. ignored and you will get a warning.</p>
  136. <h3>Examples</h3>
  137. <pre> &lt;jar file=&quot;${dist}/lib/app.jar&quot; basedir=&quot;${build}/classes&quot;/&gt;</pre>
  138. <p>jars all files in the <code>${build}/classes</code> directory into a file
  139. called <code>app.jar</code> in the <code>${dist}/lib</code> directory.</p>
  140. <pre> &lt;jar file=&quot;${dist}/lib/app.jar&quot;
  141. basedir=&quot;${build}/classes&quot;
  142. excludes=&quot;**/Test.class&quot;
  143. /&gt;</pre>
  144. <p>jars all files in the <code>${build}/classes</code> directory into a file
  145. called <code>app.jar</code> in the <code>${dist}/lib</code> directory. Files
  146. with the name <code>Test.class</code> are excluded.</p>
  147. <pre> &lt;jar file=&quot;${dist}/lib/app.jar&quot;
  148. basedir=&quot;${build}/classes&quot;
  149. includes=&quot;mypackage/test/**&quot;
  150. excludes=&quot;**/Test.class&quot;
  151. /&gt;</pre>
  152. <p>jars all files in the <code>${build}/classes</code> directory into a file
  153. called <code>app.jar</code> in the <code>${dist}/lib</code> directory. Only
  154. files under the directory <code>mypackage/test</code> are used, and files with
  155. the name <code>Test.class</code> are excluded.</p>
  156. <pre> &lt;jar file=&quot;${dist}/lib/app.jar&quot;&gt;
  157. &lt;fileset dir=&quot;${build}/classes&quot;
  158. excludes=&quot;**/Test.class&quot;
  159. /&gt;
  160. &lt;fileset dir=&quot;${src}/resources&quot;/&gt;
  161. &lt;/jar&gt;</pre>
  162. <p>jars all files in the <code>${build}/classes</code> directory and also
  163. in the <code>${src}/resources</code> directory together into a file
  164. called <code>app.jar</code> in the <code>${dist}/lib</code> directory.
  165. Files with the name <code>Test.class</code> are excluded.
  166. If there are files such as <code>${build}/classes/mypackage/MyClass.class</code>
  167. and <code>${src}/resources/mypackage/image.gif</code>, they will appear
  168. in the same directory in the JAR (and thus be considered in the same package
  169. by Java).</p>
  170. <hr>
  171. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  172. Reserved.</p>
  173. </body>
  174. </html>