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
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