My question derives from an upgrade from Tomcat 6.0.18 to 7.0.22, although it seems likely the issue arises in other versions. I suspect it stems from my misunderstanding of Tomcat's core behavior, although after a search of the Tomcat documentation, previous SO questions about Tomcat (too numerous to effectively cite), and a variety of blog posts from various sources (again not on-topic enough to be worth citing), I'm at a loss.
The application I'm working with is a sprawling java app with hundreds of JSP pages. In the past, on Tomcat 6, we've had no trouble compiling them at runtime. They (for the most part) correctly generate *_jsp.java
files within Tomcat's work directory, and the compilation to *.class files works as expected. Those that don't are legacy code that is unused in production settings, still in the codebase for reasons not worth specifying here.
When moving to Tomcat 7, specifically 7.0.22, I encountered unexpected behavior. The vast majority of the JSP pages compile (both to .java
code and to their affiliated .class
files) just fine into the work directory. Some, however, generate 0-byte .java
files.
My first take at this problem was: "Something about Tomcat JSP compilation changed between the two versions, other then the JSP specification itself." After poking around in the docs, nothing seemed obvious, so I attempted to pre-compile all the jsps using Ant.
This succeeded insofar as the conversion to .java files was concerned, using an extremely simple ant script:
<project name="myApp" default="all" basedir=".">
<import file="${tomcat.home}/bin/catalina-tasks.xml"/>
<target name="jspc">
<jasper
validateXml="false"
uriroot="${webapp.home}"
webXmlFragment="${webapp.home}/WEB-INF/generated_web.xml"
outputDir="${webapp.home}/WEB-INF/classes"
failonerror="false" />
</target>
<target name="all" depends="jspc">
</target>
</project>
*_jsp.java
files were correctly generated by jasper, and the 0-byte files that caused trouble when compiled by Tomcat into the work directory were compiling properly with this method. There were a few minor differences when compared with Tomcat 6's work directory *_jsp.java
files, but they seem likely related to the JSP spec version upgrade between 6 and 7. Unfortunately, our legacy code makes some of the resulting .java
files uncompilable, generally, in both versions. Making them compile from .java
to .class
(as opposed to .jsp
to *_jsp.java
to *_jsp.class
) would require a deep refactor. Thus, I'm unable to pursue a true JSP pre-compilation strategy. Tomcat appears to handle these files more intelligently then my scripts, which isn't at all surprising.
My question, then, is a bit broader: What might cause tomcat to generate empty *_jsp.java
files in its work directory? As a corollary, by what process does Tomcat generate those files in its work directory, and how does that differ from the way I might generate those files with an Ant script? I suspect a deeper understanding of Tomcat's core behavior might yield an obvious solution, an explainable problem, or at least an answer like "This is designed. Please refactor."