Apache » Cocoon »

  Cocoon Maven Plugin

Cocoon Maven Plugin 1.0

Shielded Classloading

Shielded classloading is an optional feature of the Cocoon deployer-plugin for Maven. It helps you in avoiding typical problems with respect to class loading. Usually the servlet container sets up a class loader for each web application. This class loader works "parent-first" which means that whenever a class is loaded it is first searched in the parent class loader of the web application class loader and only if its not available there, it is loaded from the classes in WEB-INF/classes or the jars in WEB-INF/lib. In general this is a useful mechanism which also allows you to share classes between web applications by putting them in the parent class loader (refer to the documentation of your application server/servlet engine for more information).

Unfortunately there are some problems with this approach: for example if the servlet engine has configured a logging framework like commons logging and exposes this  in the parent class loader for the web applications, than all web applications have to use this configuration and are not able to use their own. Even more important is the used XSLT processor (and some other stuff contained in the endorsed directory). By default you always use the XSLT processor shipped with the JDK; you can override this by specifying one using the endorsed mechanism but in many cases you can't use this way. As the XSLT processor shipped with the JDK has some bugs it is advisable to use the latest version.

The only reliable way of avoiding all these class loading issues is to use a mechanism we call shielded class loading: the web application uses its own class loader which works "parent-last". In this case classes are always tried to be loaded from the WEB-INF/classes or WEB-INF/lib directory first. Through this mechanism you can enforce the use of the XSLT processor you want for your application, of the logging configuration you need etc.

Some application servers provide a configuration for this, but you can also use some of the functionality provided by Cocoon: if you are using the Cocoon deploy plugin with Maven 2, this plugin rewrites your web.xml to use the shielded class loader.