|
Here is a drop -for anyone interested- of where I have got to in calling the jasper jspc class from ant. It is up the level where basic webapps and jsp pages can be compiled, but it is still very raw, some of which can be attributed to jasper -I'm using the tomcat 4.0b5 build and some things arent working there (the ieplugin tag). One thing which causes big time trouble for jasper is when ant builds the list of files down a directory tree :- <jasperc dest="build" > <source dir="jsp" includes="**/*.jsp" /> </jasperc> fails with some internal exceptions *which it doesnt report upstream to my task*. If you hand it off to jasper to do the build, things work: <jasperc dest="build" <webapp dir="jsp" /> </jasperc> I am not going to touch it for a couple of weeks, so if anyone else wants to a) fix my code, b) fix jasperc or c) write the unit test to go with the jasperc.xml, then they are welcome to do so. What I have so far seems adequate to my needs of verifying jsp page syntax before deploying and fetching all the jsp pages, it is just a bit raw. What I havent done yet is any demand generation/compilation of files as and when needed; if jasper doesnt do that then it wont happen. In 'webapp' mode it must be left to jasper; with <source> parameters we'd have to determine what the real filename/location of output java files were. java to class dependencies are addressed already, of course, with <depends> Given the tight coupling of this task to jasper, I think a jasperc task should go into jasper itself, unless we felt it was better to provide an ant facade for multiple jspc compilers (which will ultimately happen, I guess). This would help keep the ant task in perfect sync with the rest of the libraries. attached -java file (to go into optional.jspc) -html doc file (optional) -jasperc.xml (to go into src\etc\testcases\taskdefs\optional) -jsp files to go into src\etc\testcases\taskdefs\optional\jsp beneath jasper.c, except for test4.jpc which goes into jsp\subdir (to test subdir inclusion) I will get back to working on this eventually, but am somewhat distracted right now. -steve |
Jasperc.java
Description: Binary data
<?xml version="1.0"?> <project name="jasperctest" default="all" >
<target name="init">
<taskdef name="jasperc"
classname="org.apache.tools.ant.taskdefs.optional.jsp.Jasperc"/>
<mkdir dir="build"/>
</target>
<target name="test1" depends="init">
<jasperc/>
</target>
<target name="test2" depends="init">
<jasperc dest="build">
<source dir="jsp" includes="*/*.jsp" />
</jasperc>
</target>
<target name="test3" depends="init">
<jasperc dest="build"
uribase="."
uriroot="."
verbosity="1"
webinc="webinc.xml"
webxml="webxml.xml"
>
<webapp dir="jsp" />
</jasperc>
</target>
<target name="test3a" depends="init">
<jasperc dest="build"
uribase="."
uriroot="."
verbosity="4"
flatten="true">
<webapp dir="jsp" />
</jasperc>
</target>
<target name="test4" depends="init">
<jasperc dest="build"
ieplugin="CLSID:0000-0000-00000000"
verbosity="3">
<source dir="jsp" includes="testplugin.jsp" />
</jasperc>
</target>
<target name="test5" depends="init">
<jasperc dest="build"
flatten="true" verbosity="4">
<source dir="jsp" includes="**/*.jsp" />
</jasperc>
</target>
<target name="test5a" depends="init">
<jasperc dest="build"
flatten="false" verbosity="4">
<source dir="jsp" includes="**/*.jsp" />
</jasperc>
</target>
<target name="test6" depends="init">
<jasperc dest="build"
flatten="true"
webinc="webinc.xml"
webxml="webxml.xml" >
<source dir="jsp" includes="**/*.jsp" />
</jasperc>
</target>
<target name="test7" depends="init">
<jasperc verbosity="9" />
</target>
<target name="test8" depends="init">
<jasperc dest="build" mapped="true">
<source dir="jsp" includes="*/*.jsp" />
</jasperc>
</target>
</project>
test1.jsp
Description: Binary data
testplugin.jsp
Description: Binary data
test4.jsp
Description: Binary data
jasperc: compile JSP pages
This task uses Jasper to translate JSP pages to java. It can be used to precompile jsp pages for fast initial invocation of JSP pages, or simply to syntax check JSP pages without deploying them. In both cases, a javac task is usually the next stage in the build process.The task needs jasper.jar and jasper-runtime.jar, which come with builds of Tomcat 4/Catalina from the Jakarta Tomcat project
The package will be determined from the directories that the JSP page lives in. This will be relative to the web-app it live in (if it exists or is specified) or the default package. The class name will be the name of the JSP page without the extension.
To override this default value you can use the package option to sets the package name of all JSP pages compiled in the task Web-Apps specified for translation will not be affected by the option.
The directory that the resulting java files will go into is specified by the dest option. Java files will be placed in package appropriate sub directories , unless flatten is true, in which case all of the java files will be placed straight into the destination directory.
The mapped option will, if set to true, split the JSP text content into a one line per call format. There are comments above and below the mapped write calls to localize where in the JSP file each line of text comes from. This can lead to a minor performance degradation (but it is bound by a linear complexity). Without this options all adjacent writes are concatenated into a single write.
The classpath used for compilation is specified in the classpath element, as for any other classpath in ant.
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 be specified here. This should not need to be altered.
Web-App Integration
Jasperc is web-app aware. The package names and all relative uri references in JSP elements are rooted to a web-app base that is either heuristically determined or specified by the user.
uriroot specifies the root of the web application. This is where all absolute uris will be resolved from. If it is not specified then the first JSP page will be used to derive it. To derive it each parent directory of the first JSP page is searched for a WEB-INF directory, and the directory closest to the JSP page that has one will be used. If none can be found then the directory Jasperc was called from will be used. This only affects pages translated from an explicitly declared JSP file.
uribase is used to establish 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. This only affects pages translated from an explicitly declared JSP file.
The webappelement is used to specify that an entire web-app's JSP files are to be translated. The value of uriroot for that directory becomes the specified directory, and all relative uris are resolved against their position in the web app.Each directory is recursively searched and any file with a .jsp extension is parsed as though it is a JSP page. These pages obey the -d, -dd, and -p options. This recursive search is performed by the jasper libraries, and so is different from any enumeration of JSP files which ant can perform. Specifically, the jasperc package may be able to infer more about inter-JSP page relationships and dependencies if given the opportunity to build the whole webapp itself. However using ant to recursively enumerate jsp files in the <src> element enables selective inclusion and exclusion on a file by file basis. Note that the current ant task does not perform any dependency checking; the performance difference between the two specification options is likely to be minimal.
Appropriate entries for the web.xml file can be created via the webinc and webxml options. All JSP files and web-apps parsed by the single invocation will have appropriate servlet and servlet-mapping elements created for them. The webinc creates only an XML fragment suitable for inclusion into an existing web.xml file, while the webxml option creates an entire file with the appropriate headers and root elements suitable for use as a web.xml file.
Note that currently the JSP pages are compiled using the javac compiler, regardless of any override of the ant java compiler. To change this one would need to rework
Parameters
| Attribute | Description | Required |
| package | package name to put classes under | No |
| dest | destination directory | No |
| failonerror | error response flag: default=yes | No |
| flatten | boolean flag to control heirarchical/flat output. default: true | No |
| verbosity | verbosity of output -from 0 'silent' to 4 'debug info' 2 is the default | No |
| mapped | boolean to enable splitting the JSP text content into a one line per call format | No |
| sax2classname | class name for the SAX 2.0 parser to be used | No |
| classname | class name of the first JSP page to be compiled | 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, (Default is the directory jasperc is invoked from) | No |
| ieplugin | Java Plugin classid for Internet Explorer. Very rarely used | No |
| verbosity | jasperc verbosity : valid range is 0-4; default is 2 | No |
| webinc | File for the jasperc '-webinc' parameter which "creates partial servlet mappings for the -webapp option" | No |
| webxml | File referring to the web.xml file used for the webapp. | No |
Parameters specified as nested elements
source
The source element is a fileset, which specifies the jsp pages to compileclasspath
The classpath used to compile the JSP pages is specified as for any other classpath.webapp
A webapp element must contain one attribute, dir, which points to a directory containing a web application.
<jasperc
dest="build"
package="myapp.jsp"
>
<classpath>
<pathelement location="${dir.lib}" />
<pathelement path="${dir.build}" />
</classpath>
<source>
<include name="**/*.jsp"/>
</source>
<webapp directory="subdir" />
<webapp directory="subdir2" />
</jasperc>
