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 15 KiB

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