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 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 is now
  39. downgraded to being optional. The task will warn if the file is not
  40. included as an attribute or in a fileset, but still succeed. The task
  41. will also complain if more than one web.xml file is added to the JAR.
  42. </p>
  43. <p><b>Please note that the zip format allows multiple files of the same
  44. fully-qualified name to exist within a single archive. This has been
  45. documented as causing various problems for unsuspecting users. If you wish
  46. to avoid this behavior you must set the <code>duplicate</code> attribute
  47. to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
  48. <h3>Parameters</h3>
  49. <table border="1" cellpadding="2" cellspacing="0">
  50. <tr>
  51. <td valign="top"><b>Attribute</b></td>
  52. <td valign="top"><b>Description</b></td>
  53. <td align="center" valign="top"><b>Required</b></td>
  54. </tr>
  55. <tr>
  56. <td valign="top">destfile</td>
  57. <td valign="top">the WAR file to create.</td>
  58. <td align="center" valign="top" rowspan="2">Exactly one of the two.</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">warfile</td>
  62. <td valign="top"><i>Deprecated</i> name of the file to create
  63. -use <tt>destfile</tt> instead.</td>
  64. </tr>
  65. <tr>
  66. <td valign="top">webxml</td>
  67. <td valign="top">The deployment descriptor to use (WEB-INF/web.xml).</td>
  68. <td valign="top" align="center">No (since Ant1.7)</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.</td>
  138. <td valign="top" align="center">No</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">update</td>
  142. <td valign="top">indicates whether to update or overwrite
  143. the destination file if it already exists. Default is &quot;false&quot;.</td>
  144. <td valign="top" align="center">No</td>
  145. </tr>
  146. <tr>
  147. <td valign="top">duplicate</td>
  148. <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>
  149. <td valign="top" align="center">No</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">roundup</td>
  153. <td valign="top">Whether the file modification times will be
  154. rounded up to the next even number of seconds.<br>
  155. Zip archives store file modification times with a granularity of
  156. two seconds, so the times will either be rounded up or down. If
  157. you round down, the archive will always seem out-of-date when you
  158. rerun the task, so the default is to round up. Rounding up may
  159. lead to a different type of problems like JSPs inside a web
  160. archive that seem to be slightly more recent than precompiled
  161. pages, rendering precompilation useless.<br>
  162. Defaults to true. <em>Since Ant 1.6.2</em></td>
  163. <td align="center" valign="top">No</td>
  164. </tr>
  165. <tr>
  166. <td valign="top">level</td>
  167. <td valign="top">Non-default level at which file compression should be
  168. performed. Valid values range from 0 (no compression/fastest) to 9
  169. (maximum compression/slowest). <em>Since Ant 1.7</em></td>
  170. <td valign="top" align="center">No</td>
  171. </tr>
  172. </table>
  173. <h3>Nested elements</h3>
  174. <h4>lib</h4>
  175. <p>The nested <code>lib</code> element specifies a <a
  176. href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
  177. end up in the <code>WEB-INF/lib</code> directory of the war file.</p>
  178. <h4>classes</h4>
  179. <p>The nested <code>classes</code> element specifies a <a
  180. href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
  181. end up in the <code>WEB-INF/classes</code> directory of the war file.</p>
  182. <h4>webinf</h4>
  183. <p>The nested <code>webinf</code> element specifies a <a
  184. href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
  185. end up in the <code>WEB-INF</code> directory of the war file. If this
  186. fileset includes a file named <code>web.xml</code>, the file is
  187. ignored and you will get a warning.</p>
  188. <h4>metainf</h4>
  189. <p>The nested <code>metainf</code> element specifies a <a
  190. href="../CoreTypes/fileset.html">FileSet</a>. All files included in this fileset will
  191. end up in the <code>META-INF</code> directory of the war file. If this
  192. fileset includes a file named <code>MANIFEST.MF</code>, the file is
  193. ignored and you will get a warning.</p>
  194. <h3>Examples</h3>
  195. <p>Assume the following structure in the project's base directory:</p>
  196. <pre>
  197. thirdparty/libs/jdbc1.jar
  198. thirdparty/libs/jdbc2.jar
  199. build/main/com/myco/myapp/Servlet.class
  200. src/metadata/myapp.xml
  201. src/html/myapp/index.html
  202. src/jsp/myapp/front.jsp
  203. src/graphics/images/gifs/small/logo.gif
  204. src/graphics/images/gifs/large/logo.gif
  205. </pre>
  206. then the war file <code>myapp.war</code> created with
  207. <pre>
  208. &lt;war destfile=&quot;myapp.war&quot; webxml=&quot;src/metadata/myapp.xml&quot;&gt;
  209. &lt;fileset dir=&quot;src/html/myapp&quot;/&gt;
  210. &lt;fileset dir=&quot;src/jsp/myapp&quot;/&gt;
  211. &lt;lib dir=&quot;thirdparty/libs&quot;&gt;
  212. &lt;exclude name=&quot;jdbc1.jar&quot;/&gt;
  213. &lt;/lib&gt;
  214. &lt;classes dir=&quot;build/main&quot;/&gt;
  215. &lt;zipfileset dir=&quot;src/graphics/images/gifs&quot;
  216. prefix=&quot;images&quot;/&gt;
  217. &lt;/war&gt;
  218. </pre>
  219. will consist of
  220. <pre>
  221. WEB-INF/web.xml
  222. WEB-INF/lib/jdbc2.jar
  223. WEB-INF/classes/com/myco/myapp/Servlet.class
  224. META-INF/MANIFEST.MF
  225. index.html
  226. front.jsp
  227. images/small/logo.gif
  228. images/large/logo.gif
  229. </pre>
  230. using Ant's default manifest file. The content of
  231. <code>WEB-INF/web.xml</code> is identical to
  232. <code>src/metadata/myapp.xml</code>.
  233. <p>We regulary receive bug reports that this task is creating the WEB-INF
  234. directory, and thus it is our fault your webapp doesn't work. The cause
  235. of these complaints lies in WinZip, which turns an all upper-case
  236. directory into an all lower case one in a fit of helpfulness. Please check that
  237. <code>jar xvf yourwebapp.war</code> shows the same behaviour before filing another
  238. report.<br/>
  239. Winzip has an option allowing all uppercase names (which is off by default!). It can be enabled by:
  240. Menu "Options" -> "Configuration", "View" property/tab page, then "General" group box has an option called "Allow all uppercase file names".
  241. </p>
  242. </body>
  243. </html>