Why can't my webapp find classes in the WEB-INF/classes directory?

Alex Chaffee

First, you are right, Tomcat (or any servlet engine) should add classes in WEB-INF/classes to the web application's classpath. It should do the same with JAR files in the WEB-INF/lib directory.

Some suggest putting the extra classes in the TOMCAT_HOME/classes directory, but that is the wrong approach. You don't want to pollute the CLASSPATH space of other webapps. It may appear to work, but for security and architectural reasons, only official Tomcat classes should go into TOMCAT_HOME/classes.

To track down your problem, make double-extra sure that Tomcat has restarted, and that the class file is valid (i.e. it looks right "on the inside" as well as the outside -- it's been compiled with the correct package statement and so forth). You can also verify that it works by using javap, e.g.

javap -classpath mywebapp/WEB-INF/classes com.foo.Bar
should list the signatures of your com.foo.Bar class -- otherwise it's not Tomcat's fault, it's yours.

If all the above fails, then you may have encountered a bug in Tomcat, which should be discussed on tomcat-user mailing list.