I'm having the following problem. I have a Java EE application (which I didn't develop) and when I try to run it I'm getting a NoClassDefFoundError
while executing a specific functionality.
[30/12/14 11:02:40:026 CET] 00000060 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet HttpCrisServiceServlet2 in application cris-ear. Exception created : java.lang.NoClassDefFoundError: org.slf4j.MDC (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:141)
at com.foo.bar.castor.http.CastorServlet.putMDCCorrelationInfo(CastorServlet.java:214)
at com.foo.bar.castor.http.CastorServlet.service(CastorServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1602)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:149)
at com.foo.baz.server.Log4jTimingServletFilter.doFilter(Log4jTimingServletFilter.java:50)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
at be.bene.common.castor.http.CompressionFilter.doFilter(CompressionFilter.java:100)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:80)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1660)
The compiler can't find the class org.slf4j.MDC
at runtime.
Now I wanted to check if the class is on my classpath.
I used two methods to check this:
First method and output:
System.out.println(loader.getResource(MDC.class.getName().replace('.', '/') + ".class"));
00000025 SystemOut O bundleresource://352/org/slf4j/MDC.class
Second method and output:
try {
Class.forName("org.slf4j.MDC", false, loader);
System.out.println("org.slf4j.MDC does exist on the classpath (called from Log4jTiminingServletFilter)");
} catch(ClassNotFoundException e) {
System.out.println("org.slf4j.MDC does not exist on the classpath (called from Log4jTiminingServletFilter)");
}
which gave me:
00000028 SystemOut O org.slf4j.MDC does exist on the classpath (called from Log4jTiminingServletFilter)
So I assume the class is on my classpath...
But as the stacktrace tells us the problem is:
at com.foo.bar.castor.http.CastorServlet.putMDCCorrelationInfo(CastorServlet.java:214)
Now this code is 'in-house' developed, and I have (read) access to it, but I can't change it. When I check line 214, MDC is indeed called:
MDC.put(MDC_KEY_MESSAGE_UUID, CorrelationHeaderContext.getCorrelationInfo().getMessageUUID());
Now I was wondering, how can I check that org.slf4j.MDC
is also provided for the CastorServlet
, and if not, how can I provide it?