4 Replies Latest reply on Feb 19, 2008 4:20 PM by Derek Chen-Becker

    ClassNotFoundException on annotated class that's definitely

    Derek Chen-Becker Newbie

      I'm trying out JBoss 5 beta 4 and using annotations within my struts actions to set up a persistence context, essentially like:

      public class TestAction extends DispatchAction
      {
       @PersistenceContext(unitName = "foo") EntityManager em;
      ...
      


      I package the WAR up including the struts.jar, but when I deploy I get the following stack trace and the servlet is unavailable. Is this because I'm using annotations?

      08:58:50,740 WARN [TomcatInjectionContainer] could not find servlet class
       org.apache.struts.action.ActionServlet
       in classpath when processing annotations.
      08:58:51,152 WARN [TomcatInjectionContainer] could not find servlet class
       org.apache.struts.action.ActionServlet
       in classpath when processing annotations.
      08:58:51,157 INFO [[/roster]] Marking servlet action as unavailable
      08:58:51,157 ERROR [[/roster]] Servlet /roster threw load() exception
      java.lang.ClassNotFoundException:
       org.apache.struts.action.ActionServlet
      
       at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:168)
       at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1006)
       at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:950)
       at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4072)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4377)
       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
       at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
       at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
       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:585)
       at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
       at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
       at org.apache.catalina.core.StandardContext.init(StandardContext.java:5357)
       at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:346)
       at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
       at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:347)
       at org.jboss.web.deployers.WebModule.startModule(WebModule.java:89)
       at org.jboss.web.deployers.WebModule.start(WebModule.java:67)
       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:585)
       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:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
       at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:184)
       at $Proxy5.start(Unknown Source)
       at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
       at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
       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:327)
       at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:255)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
       at org.jboss.system.ServiceController.doChange(ServiceController.java:659)
       at org.jboss.system.ServiceController.start(ServiceController.java:431)
       at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:150)
       at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:108)
       at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
       at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:65)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:853)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:874)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:794)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:498)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:506)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:246)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:131)
       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:408)
       at org.jboss.Main.boot(Main.java:208)
       at org.jboss.Main$1.run(Main.java:534)
       at java.lang.Thread.run(Thread.java:595)
      


        • 1. Re: ClassNotFoundException on annotated class that's definit
          jaikiran pai Master

          Where have you placed the struts.jar in the war file? Post the output of

          jar -tf myApp.war


          where myApp is the name of your war file.

          • 2. Re: ClassNotFoundException on annotated class that's definit
            Derek Chen-Becker Newbie

            549876 Wed Feb 13 16:27:38 CST 2008 WEB-INF/lib/struts-1.2.9.jar

            The reason I'm wondering if this is specific to the annotation processing is because this WAR deploys fine in JBoss 4.2.1, although since 4.2.1 doesn't support annotations I get null pointer exceptions when I try to use the EntityManager.

            Thanks,

            Derek

            • 3. Re: ClassNotFoundException on annotated class that's definit
              Peter Johnson Master

              It could be a classloader issue. Try setting the -verbose:class JVM option on the command line. This option prints out each class loader and where it was loaded from. Compare the classes loaded by 4.2.1 to those loaded by 5.0 beta4. That might give some clues as to what is going on.

              • 4. Re: ClassNotFoundException on annotated class that's definit
                Derek Chen-Becker Newbie

                That's kind of what I was thinking. I'm not sure how to read the verbose output, but it appears that they're being loaded in different classloaders. I get the exception within the TomcatInjectionContainer, which is loaded after the ActionServlet:

                ...
                [Loaded org.apache.struts.action.ActionServlet from vfsfile:/home/dbecker/tools/jboss-5.0.0.Beta4/server/default/deploy/]
                ...
                [Loaded org.jboss.web.tomcat.service.TomcatInjectionContainer from vfsfile:/home/dbecker/tools/jboss-5.0.0.Beta4/server/default/deployers/]
                ...
                15:01:55,026 WARN [TomcatInjectionContainer] could not find servlet class
                 org.apache.struts.action.ActionServlet
                 in classpath when processing annotations.
                


                If I'm reading that correctly those are two different classloaders (.../deploy vs .../deployers). Is that correct, or am I barking up the wrong tree? In 4.2.1 the classloader messge is a little more specific:

                [Loaded org.apache.struts.action.ActionServlet from file:/home/dbecker/tools/jboss-4.2.1.GA/server/default/tmp/deploy/tmp14312roster-exp.war/WEB-INF/lib/struts-1.2.9.jar]
                


                But there is no TomcatInjectionContainer in 4.2.1 so I can't compare that.

                Derek