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.

jspc.html 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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>JSPC Task</title>
  20. </head>
  21. <body>
  22. <h2 id="jspc">jspc</h2>
  23. <h3><em><u>Deprecated</u></em></h3>
  24. <p><em>If you use this task with Tomcat's Jasper JSP compiler, you should seriously consider using
  25. the task shipping with Tomcat instead.</em> This task is only tested against Tomcat 4.x. There are
  26. known problems with Tomcat 5.x that won't get fixed in Ant, please use Tomcat's <code>jspc</code>
  27. task instead.<br/> Instead of relying on container-specific JSP compilers we suggest deploying the
  28. raw files (<samp>*.jsp</samp>) and use the container build-in functions: after deploying run a test
  29. suite (e.g. with <a href="https://attic.apache.org/projects/jakarta-cactus.html">Cactus</a>
  30. or <a href="http://httpunit.sourceforge.net/">HttpUnit</a>) against the deployed web application. So
  31. you'll get the test result <em>and</em> the compiled JSPs.</p>
  32. <h3>Description</h3>
  33. <p>Apache Ant task to run the JSP compiler and turn JSP pages into Java source files.</p>
  34. <p>This task can be used to precompile JSP pages for fast initial invocation of JSP pages,
  35. deployment on a server without the full JDK installed, or simply to syntax check the pages without
  36. deploying them. In most cases, a <code>javac</code> task is usually the next stage in the build
  37. process. The task does basic dependency checking to prevent unnecessary recompilation&mdash;this
  38. checking compares source and destination timestamps, and does not factor in class or taglib
  39. dependencies, or <code>&lt;jsp:include&gt;</code> references.</p>
  40. <p>By default the task uses the Jasper JSP compiler. This means the task
  41. needs <samp>jasper.jar</samp> and <samp>jasper-runtime.jar</samp>, which come with builds of Tomcat
  42. 4/Catalina from the <a href="https://tomcat.apache.org/">Apache Tomcat project</a>, and any other
  43. jar files which may be needed in future versions (it changes).</p>
  44. <p>We recommend (in March 2003) Tomcat version 4.1.x for the most robust version of Jasper.</p>
  45. <p>There are many limitations with this task which partially stem from the many versions of Jasper,
  46. others from implementation 'issues' in the task (i.e. nobody's willingness to radically change large
  47. bits of it to work around Jasper). Because of this and the fact that JSP pages do not have to be
  48. portable across implementations&mdash;or versions of implementations&mdash;this task is better used
  49. for validating JSP pages before deployment, rather than precompiling them. For the latter, just
  50. deploy and run your HttpUnit JUnit tests after deployment to compile and test your pages, all in one
  51. go.</p>
  52. <h3>Parameters</h3>
  53. <p>The Task has the following attributes:</p>
  54. <table class="attr">
  55. <tr>
  56. <th>Attribute</th>
  57. <th>Description</th>
  58. <th>Required</th>
  59. </tr>
  60. <tr>
  61. <td>destdir</td>
  62. <td>Where to place the generated files. They are located under here according to the given
  63. package name.</td>
  64. <td>Yes</td>
  65. </tr>
  66. <tr>
  67. <td>srcdir</td>
  68. <td>Where to look for source JSP files.</td>
  69. <td>Yes</td>
  70. </tr>
  71. <tr>
  72. <td>verbose</td>
  73. <td>The verbosity integer to pass to the compiler.</td>
  74. <td>No; default <q>0</q></td>
  75. </tr>
  76. <tr>
  77. <td>package</td>
  78. <td>Name of the destination package for generated Java classes.</td>
  79. <td>No</td>
  80. </tr>
  81. <tr>
  82. <td>compiler</td>
  83. <td>class name of a JSP compiler adapter, such as <q>jasper</q> or <q>jasper41</q></td>
  84. <td>No; defaults to <q>jasper</q></td>
  85. </tr>
  86. <tr>
  87. <td>ieplugin</td>
  88. <td>Java Plugin classid for Internet Explorer.</td>
  89. <td>No</td>
  90. </tr>
  91. <tr>
  92. <td>mapped</td>
  93. <td>(boolean) Generate separate <code>write()</code> calls for each HTML line in the JSP.</td>
  94. <td>No</td>
  95. </tr>
  96. <tr>
  97. <td>classpath</td>
  98. <td>The classpath to use to run the JSP compiler.</td>
  99. <td>No, but it seems to work better when used; can also be specified by the nested
  100. element <a href="../using.html#path"><code>classpath</code></a></td>
  101. </tr>
  102. <tr>
  103. <td>classpathref</td>
  104. <td>A <a href="../using.html#references">Reference</a>. As per <var>classpath</var>.</td>
  105. <td>No</td>
  106. </tr>
  107. <tr>
  108. <td>failonerror</td>
  109. <td>flag to control action on compile failures.</td>
  110. <td>No; default <q>yes</q></td>
  111. </tr>
  112. <tr>
  113. <td>uribase</td>
  114. <td>The context of relative URI references in JSP.</td>
  115. <td>No; derived from the location of the file relative to the declared or derived value
  116. of <var>uriroot</var></td>
  117. </tr>
  118. <tr>
  119. <td>uriroot</td>
  120. <td>The root directory that URIs should be resolved against.</td>
  121. <td>No</td>
  122. </tr>
  123. <tr>
  124. <td>compiler</td>
  125. <td>Class name of JSP compiler adapter to use.</td>
  126. <td>No; defaults to the standard adapter for Jasper</td>
  127. </tr>
  128. <tr>
  129. <td>compilerclasspath</td>
  130. <td>The classpath used to find the compiler adapter specified by the <var>compiler</var>
  131. attribute.</td>
  132. <td>No</td>
  133. </tr>
  134. <tr>
  135. <td>webinc</td>
  136. <td>Output file name for the fraction of <samp>web.xml</samp> that lists servlets.</td>
  137. <td>No</td>
  138. </tr>
  139. <tr>
  140. <td>webxml</td>
  141. <td>File name for <samp>web.xml</samp> to be generated</td>
  142. <td>No</td>
  143. </tr>
  144. </table>
  145. <p>The <var>mapped</var> option will, if set to <q>true</q>, split the JSP text content into a one
  146. line per call format. There are comments above and below the mapped write calls to localize where
  147. in the JSP file each line of text comes from. This can lead to a minor performance degradation (but
  148. it is bound by a linear complexity). Without this option all adjacent writes are concatenated into
  149. a single write.</p>
  150. <p>The <var>ieplugin</var> option is used by the <code>&lt;jsp:plugin&gt;</code> tags. If the Java
  151. Plug-in COM Class-ID you want to use changes then it can be specified here. This should not need to
  152. be altered.</p>
  153. <p><var>uriroot</var> specifies the root of the web application. This is where all absolute URIs
  154. will be resolved from. If it is not specified then the first JSP page will be used to derive it.
  155. To derive it each parent directory of the first JSP page is searched for a <samp>WEB-INF</samp>
  156. directory, and the directory closest to the JSP page that has one will be used. If none can be
  157. found then the directory Jasperc was called from will be used. This only affects pages translated
  158. from an explicitly declared JSP file&mdash;including references to taglibs.</p>
  159. <p><var>uribase</var> is used to establish the context of relative URI references in the JSP pages.
  160. If it does not exist then it is derived from the location of the file relative to the declared or
  161. derived value of <var>uriroot</var>. This only affects pages translated from an explicitly declared
  162. JSP file.</p>
  163. <h3>Parameters specified as nested elements</h3>
  164. <p>This task is a <a href="../dirtasks.html">directory based task</a>, like <code>javac</code>, so
  165. the <samp>.jsp</samp> files to be compiled are located as <samp>.java</samp> files are
  166. by <code>javac</code>. That is, elements such as <code>includes</code> and <code>excludes</code> can
  167. be used directly inside the task declaration.</p>
  168. <p>Elements specific to the <code>jspc</code> task are:</p>
  169. <h4>classpath</h4>
  170. <p>The classpath used to compile the JSP pages, specified as for any other classpath.</p>
  171. <h4>classpathref</h4>
  172. <p>a reference to an existing classpath</p>
  173. <h4>webapp</h4>
  174. <p>Instructions to Jasper to build an entire web application. The base directory must have
  175. a <samp>WEB-INF</samp> subdirectory beneath it. When used, the task hands off all dependency
  176. checking to the compiler.</p>
  177. <table class="attr">
  178. <tr>
  179. <th>Attribute</th>
  180. <th>Description</th>
  181. <th>Required</th>
  182. </tr>
  183. <tr>
  184. <td>basedir</td>
  185. <td>the base directory of the web application</td>
  186. <td>Yes</td>
  187. </tr>
  188. </table>
  189. <h3>Example</h3>
  190. <pre>
  191. &lt;jspc srcdir="${basedir}/src/war"
  192. destdir="${basedir}/gensrc"
  193. package="com.i3sp.jsp"
  194. compiler="jasper41"
  195. verbose="9"&gt;
  196. &lt;include name="**/*.jsp"/&gt;
  197. &lt;/jspc&gt;</pre>
  198. <p>Build all <samp>.jsp</samp> files under <samp>src/war</samp> into the
  199. destination <samp>/gensrc</samp>, in a package hierarchy beginning
  200. with <samp>com.i3sp.jsp</samp>.</p>
  201. <pre>
  202. &lt;jspc destdir="interim"
  203. verbose="1"
  204. srcdir="src"
  205. compiler="jasper41"
  206. package="com.i3sp.jsp"&gt;
  207. &lt;include name="**/*.jsp"/&gt;
  208. &lt;/jspc&gt;
  209. &lt;depend srcdir="interim"
  210. destdir="build"
  211. cache="build/dependencies"
  212. classpath="lib/taglibs.jar"/&gt;
  213. &lt;javac srcdir="interim"
  214. destdir="build"
  215. classpath="lib/taglibs.jar"
  216. debug="on"/&gt;</pre>
  217. <p>Generate <samp>.java</samp> files from <samp>.jsp</samp> files then <code>javac</code> them down
  218. to bytecodes. Include <samp>lib/taglibs.jar</samp> in the Java compilation. Dependency checking is
  219. used to scrub the <samp>.java</samp> files if class dependencies indicate it is needed.</p>
  220. <h4>Notes</h4>
  221. <p>Using the <var>package</var> attribute it is possible to identify the
  222. resulting <samp>.java</samp> files and thus do full dependency checking&mdash;this task should only
  223. rebuild <samp>.java</samp> files if their <samp>.jsp</samp> file has been modified. However, this
  224. only works with some versions of Jasper. By default the checking supports Tomcat 4.0.x with
  225. the <q>jasper</q> compiler, set the compiler to <q>jasper41</q> for the Tomcat 4.1.x dependency
  226. checking. Even when it does work, changes in <samp>.tld</samp> imports or in compile time includes
  227. do not get picked up.</p>
  228. <p>Jasper generates JSP pages against the JSP 1.2 specification&mdash;a copy of version 2.3 of the
  229. servlet specification is needed on the classpath to compile the Java code.</p>
  230. </body>
  231. </html>