Cari di Apache Ant 
    Apache Ant User Manual
Daftar Isi
(Sebelumnya) JlinkJUnit (Berikutnya)
Apache Ant Tasks

JspC

jspc (deprecated)

Description

Apache Ant task to run the JSP compiler and turn JSP pages into Java source.

Deprecated if you use this task with Tomcat's Jasper JSPcompiler, you should seriously consider using the task shipping withTomcat instead. This task is only tested against Tomcat 4.x. Thereare known problems with Tomcat 5.x that won't get fixed in Ant, pleaseuse Tomcat's jspc task instead.
Instead of relying on container specific JSP-compilers we suggest deploying the raw files (*.jsp) and use the container build-in functions: after deploying runa test suite (e.g. with Cactus or HttpUnit) against the deployed web application. So you'll get the test result and the compiled JSPs.

This task can be used to precompile JSP pages for fast initial invocationof JSP pages, deployment on a server without the full JDK installed,or simply to syntax check the pages without deploying them.In most cases, a javac task is usually the next stage in the build process.The task does basic dependency checking to prevent unnecessary recompilation -thischecking compares source and destination timestamps, and does not factorin class or taglib dependencies, or <jsp:include> references.

By default the task uses the Jasper JSP compiler. Thismeans the task needs jasper.jar and jasper-runtime.jar, which come withbuilds of Tomcat 4/Catalina from theApache Tomcat project,and any other Jar files which may be needed in future versions (it changes)We recommend (in March 2003) Tomcat version 4.1.x for the most robust versionof Jasper.

There are many limitations with this task which partially stem from themany versions of Jasper, others from implementation 'issues' in the task(i.e. nobody's willingness to radically change large bits of it to workaround jasper). Because of this and the fact that JSP pages do not haveto be portable across implementations -or versions of implementations-this task is better used for validating JSP pages before deployment,rather than precompiling them. For that, just deploy and run your httpunitjunit tests after deployment to compile and test your pages, all in onego.

Parameters

The Task has the following attributes:

Attribute Description Required
destdir Where to place the generated files. They are located under here according to the given package name. Yes
srcdir Where to look for source jsp files. Yes
verbose The verbosity integer to pass to the compiler. Default="0" No
package Name of the destination package for generated java classes. No
compiler class name of a JSP compiler adapter, such as "jasper" or "jasper41" No -defaults to "jasper"
ieplugin Java Plugin classid for Internet Explorer. No
mapped (boolean) Generate separate write() calls for each HTML line in the JSP. No
classpath The classpath to use to run the jsp compiler. This can also be specified by the nested element classpath Path). No, but it seems to work better when used
classpathref A Reference. As per classpath No
failonerror flag to control action on compile failures: default=yes No
uribase The uri context of relative URI references in the JSP pages. If it does not exist then it is derived from the location of the file relative to the declared or derived value of uriroot. No
uriroot The root directory that uri files should be resolved against. No
compiler Class name of jsp compiler adapter to use. Defaults to the standard adapter for Jasper. No
compilerclasspath The classpath used to find the compiler adapter specified by the compiler attribute. No
webinc Output file name for the fraction of web.xml that lists servlets. No
webxml File name for web.xml to be generated No

The mapped option will, if set to true, split the JSP text content into aone line per call format. There are comments above and below the mappedwrite calls to localize where in the JSP file each line of text comesfrom. This can lead to a minor performance degradation (but it is boundby a linear complexity). Without this options all adjacent writes areconcatenated into a single write.

The ieplugin option is used by the <jsp:plugin> tags.If the Java Plug-in COM Class-ID you want to use changes then it can bespecified here. This should not need to be altered.

uriroot specifies the root of the webapplication. This is where all absolute uris will be resolved from.If it is not specified then the first JSP page will be used to deriveit. To derive it each parent directory of the first JSP page issearched for a WEB-INF directory, and the directory closest tothe JSP page that has one will be used. If none can be found then thedirectory Jasperc was called from will be used. This only affects pagestranslated from an explicitly declared JSP file -including referencesto taglibs

uribase is used to establish the uri context ofrelative URI references in the JSP pages. If it does not exist then itis derived from the location of the file relative to the declared orderived value of uriroot. This only affects pagestranslated from an explicitly declared JSP file.

Parameters specified as nested elements

This task is a directory based task, likejavac, so the jsp files to be compiled are located as javafiles are by javac. That is, elements such as includes andexcludes can be used directly inside the task declaration.

Elements specific to the jspc task are:-

classpath

The classpath used to compile the JSP pages, specified as for any otherclasspath.

classpathref

a reference to an existing classpath

webapp

Instructions to jasper to build an entire web application.The base directory must have a WEB-INF subdirectory beneath it.When used, the task hands off all dependency checking to the compiler.
Attribute Description Required
basedir the base directory of the web application Yes

Example

<jspc srcdir="${basedir}/src/war"  destdir="${basedir}/gensrc"  package="com.i3sp.jsp"  compiler="jasper41"  verbose="9">  <include name="**/*.jsp"/></jspc>
Build all jsp pages under src/war into the destination /gensrc, in apackage hierarchy beginning with com.i3sp.jsp.
<jspc  destdir="interim"  verbose="1"  srcdir="src"  compiler="jasper41"  package="com.i3sp.jsp">  <include name="**/*.jsp"/></jspc><depend srcdir="interim" destdir="build" cache="build/dependencies" classpath="lib/taglibs.jar"/><javac srcdir="interim" destdir="build" classpath="lib/taglibs.jar" debug="on"/>
Generate jsp pages then javac them down tobytecodes. Include lib/taglib jar in the java compilation. Dependency checking is used to scrub thejava files if class dependencies indicate it is needed.

Notes

Using the package attribute it is possible to identify the resultingjava files and thus do full dependency checking - this task should only rebuildjava files if their jsp file has been modified. However, this only workswith some versions of jasper. By default the checking supports tomcat 4.0.xwith the "jasper" compiler, set the compiler to "jasper41" for the tomcat4.1.xdependency checking.Even when it does work, changes in.TLD imports or in compile time includes do not get picked up.

Jasper generates JSP pages against the JSP1.2 specification -a copy ofversion 2.3 of the servlet specification is needed on the classpath tocompile the Java code.

(Sebelumnya) JlinkJUnit (Berikutnya)