0
votes

I am somewhat confused by the Tomcat 7 classloader and its documentation.

Here is my setting:

  1. using JRE7 for Tomcat
  2. have a common.loader setting which points to several lib directories which should be loaded
  3. have several webapps, one which does XML parsing

The webapp which does XML parsing runs fine on a "clean" Tomcat without the common.loader libs. One of the common.loader libs is xercesimpl2.jar. If this JAR is present, the webapp no longer works fine (it finds an implementation of GregorianCalendan in Xerces and prefers this over the JRE java.xml.datatype Class) - the webapp only works if the JRE class is found first.

Now according to the Tomcat documentation, the class lookup prio will be "bootstrap first, than webapp/classes, webapp/lib, then common.loader) Why does the webapp not work then, if it supposedly uses the JRE classes first (which I guess are loaded by the bootstrap loader)?

If I move the xercesimpl.jar to a webapp's lib folder, the XML-parsing webapp also works, I would however require the xercesimpl.jar to be loaded by the common loader.

Any help would be greatly appreciated.

1

1 Answers

0
votes

First, if at all possible I would suggest you avoid throwing a bunch of libraries into the common loader. It has the potential to cause a lot of problems (library version issues, class cast issues, etc...) and doesn't generally give you much benefit (may save a small amount of memory).

Generally, the only thing you would put in a shared class loader, like the common loader, are drivers like JDBC or MQ. Conversely, these often work best in the common loader.

Second, there are a special class of libraries which need to be loaded using the JVM's Endorsed Standards Override Mechanism. The one that you're referring to is one of those libraries. Tomcat has some information on this here.

http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html#XML_Parsers_and_Java

Using the endorsed loading mechanism should help with your XML parser issues.