-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aparna,
On 10/3/2011 5:41 PM, aparna bejugam wrote: > Can some one tell me where to put the jsp precompilation build > file(build.xml) in the Tomcat 7 structure. You should not have to put your build.xml anywhere in the Tomcat 7 structure. Instead, you should point your build.xml file at the Tomcat 7 base installation and it should figure everything out. > I have a web application called myapp which is inside webapps > folder and has bunch of jsp files, I want to precompile them using > the following script. > > <project name="Webapp Precompilation" default="all" > basedir="../../../"> > > <property name="tomcat.home" value="${basedir}"/> Those basedir definitions definitely look weird to me. > <target name="jspc" > <taskdef classname="org.apache.jasper.JspC" > name="jasper2" > You could also do this to define all your tasks: <import file="${catalina.home}/bin/catalina-tasks.xml" /> > <classpath id="jspc.classpath"> <pathelement > location="${java.home}/../lib/tools.jar"/> You don't need tools.jar anymore. This must be really old. > <jasper2 validateXml="false" uriroot="${webapp.path}" > webxml="${outputdir}/WEB-INF/web.xml" > webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml" > outputDir="${outputdir}/WEB-INF/src"> </jasper2> Okay, does that work? Specifying webxml and webXMLFragment probably isn't necessary. > <java classname="org.apache.jasper.JspC" fork="true" > dir="${outputdir}/WEB-INF/src"> Invoking JspC again? That's just Jasper all over again. At this point, all you need to do it compile the generated .java files using <javac>. > Right now I have this build file called build.xml inside the build > folder in myapp. So final structure is myapp has bunch of jsp files > and a build folder with build.xml to precompile the jsps. When I > run the above build.xml using ant I get the following error. > > > BUILD FAILED > C:\apache-tomcat-7.0.16\webapps\myapp\build\build.xml:29: You should upgrade to 7.0.22 if you can possibly do it. I've been working on a build-jspc.xml ant script that should take care of a number of these tasks for you. Here it is in it's current form. No promises. Put the following file into catalina.home/build-jspc.xml: <?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" /> <!-- Define Jasper task with preferred classpath --> <taskdef classname="org.apache.jasper.JspC" name="jasper"> <classpath> <path refid="jspc.classpath" /> <fileset dir="${catalina.home}/bin" includes="*.jar" /> <fileset dir="${catalina.home}/lib" includes="*.jar" /> </classpath> </taskdef> <!-- 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> Now, add a target like this to your own ant build file: <target name="jspc" depends="build"> <property name="catalina.home" value="/path/to/tomcat7" /> <!-- <property name="jspc.target.dir" value="tmp" /> <!-- contains your webapp (has a WEB-INF directory, etc.) --> <property name="jspc.source.dir" value="jspc" /> <property name="jspc.jar.file" value="jsps.jar" /> <path id="jspc.classpath"> <path refid="compile.classpath" /> </path> <ant antfile="${catalina.home}/build-jspc.xml" target="jspc" inheritRefs="true" /> </target> When you run "ant jspc" you should end up with a jsps.jar file in your project's directory that contains your compiled .jsp files as well as a META-INF/web-fragment.xml file that you can merge-into your web.xml file. I'm working on getting META-INF/web-fragment.xml to be spec-3.0-compliant so you can just drop your .jar file into WEB-INF/jsps.jar and let the container take care of everything. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6LMiEACgkQ9CaO5/Lv0PDLmwCePR2X6J1/CDZy8DYmeZHJzlJJ RtQAoL0TivtEerhipWRSr/LpaAAdXme6 =tT7z -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org