Maven2, Cargo and deploying to Jetty 6 with Commons Logging
Java and it’s classloaders, always a fun time!
Every been using Maven2, Cargo and deploying to Jetty 6 with Commons Logging? Probably not, but if you were you’d run into this I bet.
org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy.
This is a Type-2 Classloader error. I know, what does that mean?
Type-II: Assignment incompatibility of two classes loaded by distinct class loaders, even in case where the two classes are bit-wise identical.
Taxonomy of class loader problems encountered when using Jakarta Commons Logging
Sweet huh? Here is the relevant section from the taxonomy. Just so you know JCL means Java Commons Logging, TCCL means Thread Context Class Loader and CFCL means Child First Class Loader.
JCL in child-first class loader trees
In child-first class loader trees, JCL suffers from problems of both Type-I and Type-II. We will start this section with an example reproducing a Type-II problem.
http://www.qos.ch/logging/classloader.jsp
Need a quick fix? The quick fix is to use SLF4J as you can see recommended in this thread on the Cargo mailing list.
The Simple Logging Facade for Java or (SLF4J) is intended to serve as a simple facade for various logging APIs allowing to the end-user to plug in the desired implementation at deployment time. SLF4J also allows for a gradual migration path away from Jakarta Commons Logging (JCL).
One last thing. If you’re running Jetty 6 and attempting to use Cargo you should know this:
Jetty in cargo at the moment is an embedded container, that is, the jetty classes have to be on the classpath at runtime. So, you can’t use the installer to install a version of jetty and then invoke a container on it.
Hi,
After tearing my hair out yesterday i found your new blog post to my undulating gratitude! I managed to fix this issue by adding the following dependencies to the cargo build plugin:
All errors are gone and i can now do integration tests! Note that i also excluded the inherent dependencies on commons-logging from my other war dependencies. Hope this helps someone who’s looking for a code sample.