Bug 57875 - Classloading guide on Servlet API classes
Summary: Classloading guide on Servlet API classes
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 8.0.21
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-30 02:35 UTC by psfung
Modified: 2015-04-30 08:39 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description psfung 2015-04-30 02:35:57 UTC
https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html
The guide writes
Any JAR file that contains Servlet API classes will be explicitly ignored by the classloader — Do not include such JARs in your web application.

I try including javaee-api-7.0.jar in my webapp in Tomcat 8. It contains Servlet API classes as well as other JEE API such as JPA and JTA. My webapp which depends on JPA and JTA runs normally, which implies the classes from javaee-api-7.0.jar are loaded.

When the same webapp is deployed in Tomcat 7, the following error is shown and my webapp failed to deploy because of NoClassDefFoundError of some JPA/JTA class.
INFO: validateJarFile(C:\apache-tomcat-7.0.54\webapps\ROOT\WEB-INF\lib\javaee-api-7.0.jar) - jar not loaded.
See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class

It appears that the classloader is changed in Tomcat 8 and that restriction is lifted. If so, please update the guide accordingly.
Comment 1 Mark Thomas 2015-04-30 08:39:27 UTC
Thanks for the report.

Tomcat 8 is more relaxed about this. It delegates first for all the JavaEE API classes for the specs Tomcat implements. This achieves the same ends with less impact on the user if they accidently ship an JavaEE API JAR in their web application.

The updated docs will be in 8.0.23 onwards.