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

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