-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John,
On 1/31/2011 10:23 AM, John Bargos wrote: > Yeah, I checked that doc b4 starting, I also checked catalina.tasks in > catalina-ant.jar and the new jasper.jar libs in the deployer\lib, so > yesterday I thought the task def was ok and I was ready to compile. I've been playing with the JSP precompiler in 7.0.x and I'm working on an ant script that I hope will ship with Tomcat in the future. I'm including it in it's current form below. All you need to do is set catalina.home to Tomcat's home directory, set a "compile.classpath" for your webapp's libraries (probably WEB-INF/lib or whatever) and then set whatever "jspc.X" properties you want to set. Currently, it will generate a web.xml fragment, but if you set "jspc.jar.file", it will even generate a JAR file that you can drop into your WEB-INF/lib directory and don't have to do your own web.xml merge. Cool, right? A couple of VERY IMPORTANT notes: 1. This is currently experimental and not very flexible. I'm trying to see what I can get out of the code without modifying it. Keep reading. 2. You need to patch lib/jasper.jar!org/apache/jasper/resources/LocalStrings.properties like this (apologies for any wrapping... just read the patch and apply it manually: it's not that complicated): > Index: java/org/apache/jasper/resources/LocalStrings.properties > =================================================================== > --- java/org/apache/jasper/resources/LocalStrings.properties (revision > 1063336) > +++ java/org/apache/jasper/resources/LocalStrings.properties (working copy) > @@ -265,31 +265,32 @@ > \ -source <version> Set the -source argument to the compiler (default > 1.6)\n\ > \ -target <version> Set the -target argument to the compiler (default > 1.6)\n\ > > -jspc.webxml.header=<?xml version="1.0" encoding="ISO-8859-1"?>\n\ > +jspc.webxml.header=<?xml version="1.0" encoding="{0}"?>\n\ > \n\ > -<!DOCTYPE web-app\n\ > -\ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"\n\ > -\ "http://java.sun.com/dtd/web-app_2_3.dtd">\n\ > +<web-app xmlns="http://java.sun.com/xml/ns/javaee"\n\ > + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\ > + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee\n\ > + http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"\n\ > + version="3.0">\n\ > <!--\n\ > -Automatically created by Apache Tomcat JspC.\n\ > +Automatically created by Apache Tomcat JspC {1, date, short} {1, time, > short}.\n\ > -->\n\ > <web-app>\n\ > \n > jspc.webxml.footer=\n\ > -</web-app>\n\ > -\n > -jspc.webinc.header=\n\ > +</web-app>\n > +jspc.webinc.header=<?xml version="1.0" encoding="{0}"?>\n\ > +\n\ > +<web-fragment xmlns="http://java.sun.com/xml/ns/javaee"\n\ > + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\ > + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee\n\ > + > http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"\n\ > + version="3.0">\n\ > <!--\n\ > -Automatically created by Apache Tomcat JspC.\n\ > -Place this fragment in the web.xml before all icon, display-name,\n\ > -description, distributable, and context-param elements.\n\ > +Automatically created by Apache Tomcat JspC {1, date, short} {1, time, > short}.\n\ > -->\n > jspc.webinc.footer=\n\ > -<!--\n\ > -All session-config, mime-mapping, welcome-file-list, error-page, taglib,\n\ > -resource-ref, security-constraint, login-config, security-role,\n\ > -env-entry, and ejb-ref elements should follow this fragment.\n\ > --->\n > +</web-fragment>\n > jspc.webinc.insertEnd=<!-- JSPC servlet mappings end --> > jspc.webinc.insertStart=<!-- JSPC servlet mappings start --> > jspc.error.jasperException=error-the file ''{0}'' generated the following > parse exception: {1} 3. It's very important that you your uriroot ("jsp.source.dir") have a WEB-INF/web.xml file that has the correct header in it, or you might get strange behavior: <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> 4. You saw different code generated by the precompiler and Jasper running within Tomcat: that's because within Tomcat, Jasper can rely on certain things being available such as tag pools. The precompiler apparently does not do tag pooling. Don't worry too much about this right now. Now that you've read all the nastiness, here's the build script: <?xml version="1.0" encoding="UTF-8" ?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - --> <project name="Tomcat-JSPC" default="" basedir="."> <import file="${catalina.home}/bin/catalina-tasks.xml" /> <target name="jspc" description="Compiles JSPs" depends="jspc:jasper, jspc:javac, jspc:jar"> </target> <target name="jspc:jasper"> <condition property="jspc-configuration-okay"> <and> <isset property="catalina.home" /> <isset property="jspc.target.dir" /> <isset property="jspc.source.dir" /> <resourcecount refid="compile.classpath" when="greater" count="0" /> </and> </condition> <fail unless="jspc-configuration-okay"> JspC requires the following properties to be set: catalina.home=${catalina.home} jspc.target.dir=${jspc.target.dir} jspc.source.dir=${jspc.source.dir} Also, you need to have the following classpath reference set: <path id="jspc.classpath"> It should point to all of the classes and libraries referenced by your JSP sources. </fail> <delete dir="${jspc.target.dir}" /> <mkdir dir="${jspc.target.dir}" /> <mkdir dir="${jspc.target.dir}/src" /> <mkdir dir="${jspc.target.dir}/classes" /> <mkdir dir="${jspc.target.dir}/META-INF" /> <!-- Invoke Jasper --> <jasper compile="false" uriroot="${jspc.source.dir}" outputDir="${jspc.target.dir}/src" webXmlFragment="${jspc.target.dir}/META-INF/web-fragment.xml"> </jasper> </target> <target name="jspc:javac"> <!-- Compile the classes --> <javac srcdir="${jspc.target.dir}/src" destdir="${jspc.target.dir}/classes" deprecation="${javac.deprecation}" includeAntRuntime="false"> <classpath> <path refid="jspc.classpath" /> <fileset dir="${catalina.home}/lib" includes="*.jar" /> </classpath> </javac> </target> <target name="jspc:jar" if="jspc.jar.file"> <!-- Package into a .jar file --> <jar destfile="${jspc.jar.file}" compress="true"> <fileset dir="${jspc.target.dir}" includes="META-INF/web-fragment.xml" /> <fileset dir="${jspc.target.dir}/classes" includes="**/*" /> </jar> </target> </project> Let me know how it goes. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1HPNYACgkQ9CaO5/Lv0PAQXgCfSgSZ7zwFIgJW9rtkYDC/a1Uy 8aYAoKCiFx1ddRTbXNiYIOXPrR7ogndP =biHz -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org