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