• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError error  RSS feed

 
Julie Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I am having a class problem I thought I might share in the hopes someone has a suggestion for resolving. (I’m at a loss).

I am trying to use the following code to load a class :

Class actionClass = Class.forName("com.abc.actions.message.EditXMLPrologAction");


In total, there are 3 classes from the net/socialchange/doctype package that the EditXMLPrologAction class imports.
import net.socialchange.doctype.Doctype;
import net.socialchange.doctype.DoctypeChangerStream;
import net.socialchange.doctype.DoctypeGenerator;

The above line of code throws the following exception

2012-01-16 15:20:13,899 (15 ) [Thread-2] WARN com.abc.channels.tools.ChannelToolsSchedulingServlet - Exception while creating action class
java.lang.NoClassDefFoundError: net/socialchange/doctype/DoctypeGenerator
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.abc.channels.tools.ChannelToolsSchedulingServlet.runClassCheck(ChannelToolsSchedulingServlet.java:175)
at com.abc.channels.tools.ChannelToolsSchedulingServlet.init(ChannelToolsSchedulingServlet.java:82)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1208)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1108)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3628)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3851)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:294)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:146)
at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:476)
at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
at org.jboss.web.deployers.WebModule.start(WebModule.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:271)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:670)
at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
at $Proxy41.start(Unknown Source)
at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:53)
at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:41)
at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379)
at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:301)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654)
at org.jboss.system.ServiceController.doChange(ServiceController.java:671)
at org.jboss.system.ServiceController.start(ServiceController.java:443)
at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:189)
at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:102)
at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:49)
at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:63)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1832)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1550)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1571)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1603)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1491)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654)
at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679)
at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106)
at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:143)
at org.jboss.profileservice.dependency.ProfileDeployAction.deploy(ProfileDeployAction.java:151)
at org.jboss.profileservice.dependency.ProfileDeployAction.installActionInternal(ProfileDeployAction.java:94)
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654)
at org.jboss.profileservice.dependency.ProfileActivationWrapper$BasicProfileActivation.start(ProfileActivationWrapper.java:190)
at org.jboss.profileservice.dependency.ProfileActivationWrapper.start(ProfileActivationWrapper.java:87)
at org.jboss.profileservice.dependency.ProfileActivationService.activateProfile(ProfileActivationService.java:215)
at org.jboss.profileservice.dependency.ProfileActivationService.activate(ProfileActivationService.java:159)
at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.activate(AbstractProfileServiceBootstrap.java:112)
at org.jboss.profileservice.resolver.BasicResolverFactory$ProfileResolverFacade.deploy(BasicResolverFactory.java:87)
at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.start(AbstractProfileServiceBootstrap.java:91)
at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:132)
at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56)
at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827)
at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: net.socialchange.doctype.DoctypeGenerator from BaseClassLoader@15db93c{vfs:///E:/jboss-6.1.0.Final/server/server2/AbcApps/Channels.ear}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 91 more



If I comment out the use of DoctypeGenerator within the EditXMLprolog class, then I get the same error as above, but with the net/socialchange/doctype/DoctypeChangerStream

When I comment out all 3 classes, EditXMLProlog loads successfully.

Sounds like a classpath problem RIGHT??
I thought so too.
I checked classpaths etc and all looks ok.

So I did the following :

In the same class that I try to load up the EditXMLProlog, I try instantiating the DoctypeChangerStream class.
And it works just fine.


Here is the code (with liberal logging statements) -


And here is the output (with the socialchange packages commented out of the EditXMLProlog class) :

DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - net.socialchange.doctype.DoctypeGenerator
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 1
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 2
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 3
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - com.abc.actions.message.EditXMLPrologAction
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - Finished finding dodgy Class


And here is the output (with the socialchange packages NOT commented out of the EditXMLProlog class) :

DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - net.socialchange.doctype.DoctypeGenerator
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 1
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 2
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - 3
DEBUG com.abc.channels.tools.ChannelToolsSchedulingServlet - JH - finding dodgy Class - com.abc.actions.message.EditXMLPrologAction
WARN com.abc.channels.tools.ChannelToolsSchedulingServlet - Exception while creating action class
java.lang.NoClassDefFoundError: net/socialchange/doctype/DoctypeGenerator
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.abc.channels.tools.ChannelToolsSchedulingServlet.runClassCheck(ChannelToolsSchedulingServlet.java:175)
at com.abc.channels.tools.ChannelToolsSchedulingServlet.init(ChannelToolsSchedulingServlet.java:82)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1208)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1108)

....rest of stack trace as above


So the code is happy to instantiate the DoctypeChangerStream class, and do a forName() on the DoctypeGenerator class.

BUT

Not happy to do a forName on the EditXMLPrologAction when it IMPORTS (and uses) the socialchange package classes.


I would have thought that if it was an issue with not being able to find the net/socialchange/doctype package, then the code would error when trying to instatiate these classes.


Does anyone have any suggestions as to what the issue might be, or some further testing I could do to narrow down the problem.


Thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run your program, you must make sure that the classes that are in the net.socialchange.doctype package are in the classpath.

If this is a web application (in a WAR file), this most likely means that you must make sure the appropriate library is added to the WEB-INF/lib directory of the WAR file.
 
Julie Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Jesper
Thanks for your response.
However I believe that those classes (packaged in a jar) are already in my classpath.
As I mentioned in my original post, I can successfully instantiate the net.socialchange.doctype classes from within the servlet.
But the problem occurs when I attempt to load a class which itself imports and uses classes from that package.
If the classes were not in my classpath, then surely I would also get a CLassNotFound exception when attempting to instantiate the net.socialchange.doctype classes?

 
Julie Kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have sorted out the problem.
I believe it was a classloader issue - but not sure exactly how.

Here is my explanation.

My ear contained a web application and an ejb application.

In a servlet in my WebApplication, I used a class called EditXMLProlog, which is contained in a jar called actions-bpm.jar
The EDitXMLProlog class uses classes from the socialchange package. The classes from the socialchange package are in a jar called DocChanger.jar.

The classpath for my web application contained both the actions-bpm.jar and the DocChanger.jar HOWEVER, the classpath for my EJB application contained only the actions-bpm.jar (the ejb is using another class within that jar), and NOT the DocChanger.jar.

When my web application tried to load the EditXMLProlog class, I think it must have tried to load the EditXMLProlog class in the the EJBs class loader, and not the web applications classloader. This would explain why it could not find the socialchange class when referenced from within the EditXMLProlog class, but COULD load the socialchange class when loaded directly from the servlet.

When I added the socialchange package into the EJBs classpath, the servlet could successfully load the EditXMLProlog class.

I am not sure of the intricacies of the heirarchy of classloaders and when one classloader is used in preference to another, but this is the only explanation I can come up with.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!