The Artima Developer Community
Sponsored Link

Java Buzz Forum
Tomcat 5.0 Precompile with Struts and Tiles

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Cal Holman

Posts: 18
Nickname: holmanc
Registered: Aug, 2003

Cal Holman is Manager for Web Applications at Paymentech
Tomcat 5.0 Precompile with Struts and Tiles Posted: Nov 2, 2003 9:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Cal Holman.
Original Post: Tomcat 5.0 Precompile with Struts and Tiles
Feed Title: Cal Holman's Blog
Feed URL: http://www.calandva.com/holmansite/do/rss/CreateRssFile?type=blog
Feed Description: CalAndVA.com is built on many Java Open Source projects - this is a blog on the site progress
Latest Java Buzz Posts
Latest Java Buzz Posts by Cal Holman
Latest Posts From Cal Holman's Blog

Advertisement

Adding precompiled jsps with Tomcat 5 is actually pretty easy to bring into the build process.  First the environment - I was trying to precompile jsps built on Struts 1.1 and Tiles.  My previous attempts in Tomcat 3 were foiled by the complexity of the process.  In Tomcat 5 the documentation provides a good example of setting up the Jasper 2 compiler to precompile your application.

The key is to create the exploded WAR and then invoke the jspc and javac on that structure.  Since they both need all the classes, libraries, and jsps.  My development project structure is below.  The Tomcat example does the precompile on the exploded war in the webapps directory - I use a build directory to pull all the items together prior to making a war file.

First you create the servlets - in following the example I placed them in the WEB-INF directory.  Then you compile the servlets and for me they were compiled into the build/classes directory. Next you need to map all the new servlets to the .jsp requests so I replace a token with the generated_web.xml in my web.xml.  This last step makes the build process automated but means your web.xml is built by ant.  I have not included the compile and war targets.

project
-->src           <-- all .java files

-->build
---->classes     <-- all classes including precompiled jsps
---->WEB-INF 
---->META-INF

-->WebRoot
---->web          <-- html/jsp/css/etc
---->META-INF
---->WEB-INF
------>classes    <-- compiled classes from the project/src the real java classes
------>src        <-- used to store the jsp servlets created in jspc target
------>lib

 <target name="jspc">
  <delete dir="${WEB-INF.dir}/src"/>
 <taskdef    name="jasper2"   classname="org.apache.jasper.JspC" >
  <classpath id="jspc.classpath">
  <pathelement location="${java.home}/../lib/tools.jar"/>
  <fileset dir="${my.catalina.home}/server/lib">
   <include name="*.jar"/>
  </fileset>
  <fileset dir="${my.catalina.home}/common/lib">
     <include name="*.jar"/>
  </fileset>
  </classpath>
 </taskdef>
 
 <jasper2
  validateXml="false"
  uriroot="${WebRoot.dir}"
  webXmlFragment="${WEB-INF.dir}/generated_web.xml"
  outputDir="${WEB-INF.dir}/src" />

</target>
<target name="compilejsp">
 
 <javac  destdir="${build.classes.dir}"
     optimize="off"
     debug="on"
     failonerror="false"
     srcdir="${WEB-INF.dir}/src"
     excludes="**/*.smap">
 
 <classpath>
  <pathelement location="${WEB-INF.dir}/classes"/>
  <fileset dir="${WEB-INF.dir}/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/common/classes"/>
  <fileset dir="${my.catalina.home}/common/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/shared/classes"/>
  <fileset dir="${my.catalina.home}/shared/lib">
   <include name="*.jar"/>
  </fileset>
 </classpath>
 <include name="**" />
 <exclude name="tags/**" />
</javac>

    </target>

<target name="compile-jsps" depends="init, compile, jspc,compilejsp">
 <loadfile property="file" srcFile="${WEB-INF.dir}/generated_web.xml"/>
 <copy    file="${ant.template.dir}/web.xml"  
  toFile="${WEB-INF.dir}/web.xml"  filtering="on" overwrite="yes">
  <filterset>
   <filter  token="generated"  value="${file}"/>
  </filterset>
 </copy>  
</target>

Read: Tomcat 5.0 Precompile with Struts and Tiles

Topic: Master-King Previous Topic   Next Topic Topic: Struts Article

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use