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.9 KiB

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