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.

war.html 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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>WAR Task</title>
  20. </head>
  21. <body>
  22. <h2 id="war">War</h2>
  23. <h3>Description</h3>
  24. <p>An extension of the <a href="jar.html">Jar</a> task with special treatment for files that should
  25. end up in the <samp>WEB-INF/lib</samp>, <samp>WEB-INF/classes</samp> or <samp>WEB-INF</samp>
  26. directories of the Web Application Archive.</p>
  27. <p>(The <code>War</code> task is a shortcut for specifying the particular layout of a WAR file. The
  28. same thing can be accomplished by using the <var>prefix</var> and <var>fullpath</var> attributes
  29. of <code>zipfileset</code>s in a <code>Zip</code> or <code>Jar</code> task.)</p>
  30. <p>The extended <code>zipfileset</code> element from the <code>zip</code> task (with
  31. attributes <var>prefix</var>, <var>fullpath</var>, and <var>src</var>) is available in
  32. the <code>War</code> task. The task is also resource-enabled and will add nested resources and
  33. resource collections to the archive.</p>
  34. <p>Before Servlet API 2.5/Java EE 5, a <samp>WEB-INF/web.xml</samp> file was mandatory in a WAR
  35. file, so this task failed if the <var>webxml</var> attribute was missing. As
  36. the <samp>web.xml</samp> file is now optional, the <var>webxml</var> attribute may now be made
  37. optional. However, as most real web applications do need a <samp>web.xml</samp> file, it is not
  38. optional by default. The task will fail if the file is not included, unless
  39. the <var>needxmlfile</var> attribute is set to <q>false</q>. The task will warn if more than
  40. one <samp>web.xml</samp> file is added to the JAR through the filesets.</p>
  41. <p><strong>Please note that the Zip format allows multiple files of the same fully-qualified name to
  42. exist within a single archive. This has been documented as causing various problems for
  43. unsuspecting users. If you wish to avoid this behavior you must set the <var>duplicate</var>
  44. attribute to a value other than its default, <q>add</q>.</strong></p>
  45. <h3>Parameters</h3>
  46. <table class="attr">
  47. <tr>
  48. <th>Attribute</th>
  49. <th>Description</th>
  50. <th>Required</th>
  51. </tr>
  52. <tr>
  53. <td>destfile</td>
  54. <td>the WAR file to create.</td>
  55. <td rowspan="2">Exactly one of the two</td>
  56. </tr>
  57. <tr>
  58. <td>warfile</td>
  59. <td class="left"><em><u>Deprecated</u></em> name of the file to
  60. create&mdash;use <var>destfile</var> instead.</td>
  61. </tr>
  62. <tr>
  63. <td>webxml</td>
  64. <td>The servlet configuration descriptor to use (<samp>WEB-INF/web.xml</samp>).</td>
  65. <td>Yes, unless <var>needxmlfile</var> is <q>true</q>, the file is pulled in via a nested
  66. fileset, or an existing WAR file is being updated.</td>
  67. </tr>
  68. <tr>
  69. <td>needxmlfile</td>
  70. <td>Flag to indicate whether or not the <samp>web.xml</samp> file is needed. It should be set
  71. to <q>false</q> when generating servlet 2.5+ WAR files without a <samp>web.xml</samp>
  72. file. <em>Since Apache Ant 1.7</em></td>
  73. <td>No; default is <q>true</q></td>
  74. </tr>
  75. <tr>
  76. <td>basedir</td>
  77. <td>the directory from which to jar the files.</td>
  78. <td>No</td>
  79. </tr>
  80. <tr>
  81. <td>compress</td>
  82. <td>Not only store data but also compress them. Unless you set the <var>keepcompression</var>
  83. attribute to <q>false</q>, this will apply to the entire archive, not only the files you've
  84. added while updating.</td>
  85. <td>No; defaults to <q>true</q></td>
  86. </tr>
  87. <tr>
  88. <td>keepcompression</td>
  89. <td>For entries coming from existing archives (like nested <var>zipfileset</var>s or while
  90. updating the archive), keep the compression as it has been originally instead of using
  91. the <var>compress</var> attribute. <em>Since Ant 1.6</em></td>
  92. <td>No; defaults to <q>false</q></td>
  93. </tr>
  94. <tr>
  95. <td>encoding</td>
  96. <td>The character encoding to use for filenames inside the archive. <strong>It is not
  97. recommended to change this value as the created archive will most likely be unreadable for
  98. Java otherwise.</strong> <br/>See also the <a href="zip.html#encoding">discussion in the zip
  99. task page</a></td>
  100. <td>No; defaults to <q>UTF8</q></td>
  101. </tr>
  102. <tr>
  103. <td>filesonly</td>
  104. <td>Store only file entries</td>
  105. <td>No; defaults to <q>false</q></td>
  106. </tr>
  107. <tr>
  108. <td>includes</td>
  109. <td>Comma- or space-separated list of patterns of files that must be included.</td>
  110. <td>No; defaults to all (<q>**</q>)</td>
  111. </tr>
  112. <tr>
  113. <td>includesfile</td>
  114. <td>Name of a file. Each line of this file is taken to be an include pattern</td>
  115. <td>No</td>
  116. </tr>
  117. <tr>
  118. <td>excludes</td>
  119. <td>Comma- or space-separated list of patterns of files that must be excluded.</td>
  120. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  121. </tr>
  122. <tr>
  123. <td>excludesfile</td>
  124. <td>Name of a file. Each line of this file is taken to be an exclude pattern</td>
  125. <td>No</td>
  126. </tr>
  127. <tr>
  128. <td>defaultexcludes</td>
  129. <td>Indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  130. <td>No; defaults to <q>yes</q></td>
  131. </tr>
  132. <tr>
  133. <td>manifest</td>
  134. <td>the manifest file to use.</td>
  135. <td>No</td>
  136. </tr>
  137. <tr>
  138. <td>filesetmanifest</td>
  139. <td>behavior when a manifest is found in a <code>zipfileset</code>
  140. or <code>zipgroupfileset</code> file. Valid values are <q>skip</q>, <q>merge</q>,
  141. and <q>mergewithoutmain</q>. <q>merge</q> will merge all of the manifests together, and merge
  142. this into any other specified manifests. <q>mergewithoutmain</q> merges everything but the
  143. Main section of the manifests.
  144. </td>
  145. <td>No; defaults to <q>skip</q></td>
  146. </tr>
  147. <tr>
  148. <td>whenmanifestonly</td>
  149. <td>behavior when no files match. Valid values are <q>fail</q>, <q>skip</q>,
  150. and <q>create</q>.</td>
  151. <td>No; defaults to <q>create</q></td>
  152. </tr>
  153. <tr>
  154. <td>update</td>
  155. <td>indicates whether to update or overwrite the destination file if it already exists.</td>
  156. <td>No; defaults to <q>false</q></td>
  157. </tr>
  158. <tr>
  159. <td>duplicate</td>
  160. <td>behavior when a duplicate file is found. Valid values are <q>add</q>, <q>preserve</q>,
  161. and <q>fail</q>.</td>
  162. <td>No; defaults to <q>add</q></td>
  163. </tr>
  164. <tr>
  165. <td>roundup</td>
  166. <td>Whether the file modification times will be rounded up to the next even number of
  167. seconds.<br/>Zip archives store file modification times with a granularity of 2 seconds, so
  168. the times will either be rounded up or down. If you round down, the archive will always seem
  169. out-of-date when you rerun the task, so the default is to round up. Rounding up may lead to a
  170. different type of problems like JSPs inside a web archive that seem to be slightly more recent
  171. than precompiled pages, rendering precompilation useless. <em>Since Ant 1.6.2</em></td>
  172. <td>No; defaults to <q>true</q></td>
  173. </tr>
  174. <tr>
  175. <td>level</td>
  176. <td>Non-default level at which file compression should be performed. Valid values range
  177. from <q>0</q> (no compression/fastest) to <q>9</q> (maximum compression/slowest). <em>Since
  178. Ant 1.7</em></td>
  179. <td>No</td>
  180. </tr>
  181. <tr>
  182. <td>preserve0permissions</td>
  183. <td>when updating an archive or adding entries from a different archive Ant will assume that a
  184. Unix permissions value of 0 (nobody is allowed to do anything to the file/directory) means
  185. that the permissions haven't been stored at all rather than real permissions and will instead
  186. apply its own default values.<br/> Set this attribute to <q>true</q> if you really want to
  187. preserve the original permission field. <em>since Ant 1.8.0</em></td>
  188. <td>No; default is <q>false</q></td>
  189. </tr>
  190. <tr>
  191. <td>useLanguageEncodingFlag</td>
  192. <td>Whether to set the language encoding flag if the encoding is UTF-8. This setting doesn't
  193. have any effect if the encoding is not UTF-8. <em>Since Ant 1.8.0</em>. <br/>See also
  194. the <a href="zip.html#encoding">discussion in the zip task page</a></td>
  195. <td>No; default is <q>true</q></td>
  196. </tr>
  197. <tr>
  198. <td>createUnicodeExtraFields</td>
  199. <td>Whether to create Unicode extra fields to store the file names a second time inside the
  200. entry's metadata.<br/>Possible values are <q>never</q>, <q>always</q>
  201. and <q>not-encodeable</q> which will only add Unicode extra fields if the file name cannot be
  202. encoded using the specified encoding. <em>Since Ant 1.8.0</em>.<br/>See also
  203. the <a href="zip.html#encoding">discussion in the zip task page</a></td>
  204. <td>No; default is <q>never</q></td>
  205. </tr>
  206. <tr>
  207. <td>fallbacktoUTF8</td>
  208. <td>Whether to use UTF-8 and the language encoding flag instead of the specified encoding if a
  209. file name cannot be encoded using the specified encoding. <em>Since Ant 1.8.0</em>.<br/>See
  210. also the <a href="zip.html#encoding">discussion in the zip task page</a></td>
  211. <td>No; default is <q>false</q></td>
  212. </tr>
  213. <tr>
  214. <td>mergeClassPathAttributes</td>
  215. <td>Whether to merge the <code>Class-Path</code> attributes found in different manifests (if
  216. merging manifests). If <q>false</q>, only the attribute of the last merged manifest will be
  217. preserved. <em>Since Ant 1.8.0</em>.<br/>Unless you also set <var>flattenAttributes</var>
  218. to <q>true</q> this may result in manifests containing multiple <code>Class-Path</code>
  219. attributes which violates the manifest specification.</td>
  220. <td>No; default is false</td>
  221. </tr>
  222. <tr>
  223. <td>flattenAttributes</td>
  224. <td>Whether to merge attributes occurring more than once in a section (this can only happen for
  225. the <code>Class-Path</code> attribute) into a single attribute. <em>Since Ant 1.8.0</em>.</td>
  226. <td>No; default is <q>false</q></td>
  227. </tr>
  228. <tr>
  229. <td>zip64Mode</td>
  230. <td>When to use Zip64 extensions for entries. The possible values
  231. are <q>never</q>, <q>always</q> and <q>as-needed</q>. <em>Since Ant 1.9.1</em>.<br/>See also
  232. the <a href="zip.html#zip64">discussion in the zip task page</a></td>
  233. <td>No; default is <q>never</q></td>
  234. </tr>
  235. </table>
  236. <h3>Parameters specified as nested elements</h3>
  237. <h4>lib</h4>
  238. <p>The nested <code>lib</code> element specifies a <a href="../Types/fileset.html">FileSet</a>. All
  239. files included in this fileset will end up in the <samp>WEB-INF/lib</samp> directory of the war
  240. file.</p>
  241. <h4>classes</h4>
  242. <p>The nested <code>classes</code> element specifies
  243. a <a href="../Types/fileset.html">FileSet</a>. All files included in this fileset will end up in
  244. the <samp>WEB-INF/classes</samp> directory of the war file.</p>
  245. <h4>webinf</h4>
  246. <p>The nested <code>webinf</code> element specifies
  247. a <a href="../Types/fileset.html">FileSet</a>. All files included in this fileset will end up in
  248. the <samp>WEB-INF</samp> directory of the war file. If this fileset includes a file
  249. named <samp>web.xml</samp>, the file is ignored and you will get a warning.</p>
  250. <h4>metainf</h4>
  251. <p>The nested <code>metainf</code> element specifies
  252. a <a href="../Types/fileset.html">FileSet</a>. All files included in this fileset will end up in
  253. the <samp>META-INF</samp> directory of the war file. If this fileset includes a file
  254. named <samp>MANIFEST.MF</samp>, the file is ignored and you will get a warning.</p>
  255. <h4>manifest, indexjars, service</h4>
  256. These are inherited from <a href="jar.html">&lt;jar&gt;</a>
  257. <h3>Examples</h3>
  258. <p>Assume the following structure in the project's base directory:</p>
  259. <pre>
  260. thirdparty/libs/jdbc1.jar
  261. thirdparty/libs/jdbc2.jar
  262. build/main/com/myco/myapp/Servlet.class
  263. src/metadata/myapp.xml
  264. src/html/myapp/index.html
  265. src/jsp/myapp/front.jsp
  266. src/graphics/images/gifs/small/logo.gif
  267. src/graphics/images/gifs/large/logo.gif</pre>
  268. then the war file <samp>myapp.war</samp> created with
  269. <pre>
  270. &lt;war destfile=&quot;myapp.war&quot; webxml=&quot;src/metadata/myapp.xml&quot;&gt;
  271. &lt;fileset dir=&quot;src/html/myapp&quot;/&gt;
  272. &lt;fileset dir=&quot;src/jsp/myapp&quot;/&gt;
  273. &lt;lib dir=&quot;thirdparty/libs&quot;&gt;
  274. &lt;exclude name=&quot;jdbc1.jar&quot;/&gt;
  275. &lt;/lib&gt;
  276. &lt;classes dir=&quot;build/main&quot;/&gt;
  277. &lt;zipfileset dir=&quot;src/graphics/images/gifs&quot;
  278. prefix=&quot;images&quot;/&gt;
  279. &lt;/war&gt;</pre>
  280. <p>will consist of</p>
  281. <pre>
  282. WEB-INF/web.xml
  283. WEB-INF/lib/jdbc2.jar
  284. WEB-INF/classes/com/myco/myapp/Servlet.class
  285. META-INF/MANIFEST.MF
  286. index.html
  287. front.jsp
  288. images/small/logo.gif
  289. images/large/logo.gif</pre>
  290. using Ant's default manifest file. The content of
  291. <samp>WEB-INF/web.xml</samp> is identical to
  292. <samp>src/metadata/myapp.xml</samp>.
  293. <p>We regularly receive bug reports that this task is creating the <samp>WEB-INF</samp> directory
  294. as <samp>web-inf</samp> (all lower case), and thus it is our fault your webapp doesn't work. The
  295. cause of these complaints lies in WinZip, which turns an all upper-case directory into an all
  296. lower-case one in a fit of helpfulness. Please check that <code>jar xvf yourwebapp.war</code> shows
  297. the same behaviour before filing another report.<br/>WinZip has an option allowing all uppercase
  298. names (which is off by default!). It can be enabled by: Menu <q>Options</q>
  299. &rarr; <q>Configuration</q>, <q>View</q> property/tab page, then <q>General</q> group box has an
  300. option called <q>Allow all uppercase file names</q>.</p>
  301. </body>
  302. </html>