1 Reply Latest reply on Aug 18, 2011 3:16 AM by jaikiran pai

    ClassNotFoundException: javax.servlet.ServletContextListener

    Shelley Baker Newbie

      I have a Java EE 5 application (attached) with contents as follows (I've narrowed down my real application to the following test case which isolates the problem):

      |- META-INF/application.xml (declares web-module.war)
      |- web-module.war (servlet 2.5 web module)
         |- WEB-INF/web.xml (declares WebInitializer as listener)
         |- META-INF/MANIFEST.MF (Class-Path: ee-components-1.0-SNAPSHOT.jar java-beans-1.0-SNAPSHOT.jar)
      |- ee-components.jar
         |- test/sjb/components/WebInitializer (simple ServletContextListener that depends on test.sjb.beans.Pojo) |- java-beans.jar
         |- test/sjb/beans/Pojo (simple java class with no dependencies)

      When attempting to deploy this application on JBoss AS 7.0.0.Final, the following exception occurs:

      10:28:34,603 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-16) Starting deployment of "test-app.ear"

      10:28:34,644 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-15) Starting deployment of "web-module.war"

      10:28:34,692 WARN  [org.jboss.modules] (MSC service thread 1-11) Failed to define class test.sjb.components.WebInitializer in Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link test/sjb/components/WebInitializer (Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main" from Service Module Loader)

          at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)

          at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)

          at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)

          at org.jboss.modules.Module.loadModuleClass(Module.java:588)

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

          at java.lang.Class.forName0(Native Method) [:1.6.0_26]

          at java.lang.Class.forName(Class.java:247) [:1.6.0_26]

          at org.jboss.as.ee.component.EEClassConfigurationProcessor.processClasses(EEClassConfigurationProcessor.java:126)

          at org.jboss.as.ee.component.EEClassConfigurationProcessor.deploy(EEClassConfigurationProcessor.java:76)

          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

          at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

          at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

      Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener

          at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_26]

          at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_26]

          at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_26]

          at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_26]

          at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)

          ... 18 more

      Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener from [Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main" from Service Module Loader]

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

          ... 23 more

       

      10:28:34,695 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-11) MSC00001: Failed to start service jboss.deployment.unit."test-app.ear".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."test-app.ear".INSTALL: Failed to process phase INSTALL of deployment "test-app.ear"

          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

          at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

          at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

      Caused by: java.lang.LinkageError: Failed to link test/sjb/components/WebInitializer (Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main" from Service Module Loader)

          at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)

          at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)

          at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)

          at org.jboss.modules.Module.loadModuleClass(Module.java:588)

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

          at java.lang.Class.forName0(Native Method) [:1.6.0_26]

          at java.lang.Class.forName(Class.java:247) [:1.6.0_26]

          at org.jboss.as.ee.component.EEClassConfigurationProcessor.processClasses(EEClassConfigurationProcessor.java:126)

          at org.jboss.as.ee.component.EEClassConfigurationProcessor.deploy(EEClassConfigurationProcessor.java:76)

          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

          ... 5 more

      Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener

          at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_26]

          at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_26]

          at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_26]

          at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_26]

          at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)

          ... 18 more

      Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener from [Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main" from Service Module Loader]

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

          ... 23 more

       

      10:28:34,905 INFO  [org.jboss.as.server.controller] (pool-2-thread-2) Deployment of "test-app.ear" was rolled back with failure message {"Failed services" => {"jboss.deployment.unit.\"test-app.ear\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test-app.ear\".INSTALL: Failed to process phase INSTALL of deployment \"test-app.ear\""},"Services with missing/unavailable dependencies" => ["jboss.naming.context.java.comp.test-app.web-module.web-module.ValidatorFactory missing [ jboss.naming.context.java.module.test-app.web-module ]","jboss.naming.context.java.comp.test-app.web-module.web-module.Validator missing [ jboss.naming.context.java.module.test-app.web-module ]"]}

      10:28:34,926 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) Stopped deployment web-module.war in 22ms

      10:28:34,935 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-12) Stopped deployment test-app.ear in 33ms

      The application represents a typical, simplified "skinny WAR" where the libraries are bundled within the EAR and referenced from the web module's MANFIFEST.MF. The web module correctly declares its dependencies on the Manifest Class-Path, and all JARs should be visible to it. The javax.* Java EE classes should be provided by the container and visible to the module, so I'm not sure why the ClassNotFoundException exception is being thrown. This same application deploys and runs fine on JBoss 6.0.0.Final, as well as some other application servers (including WAS 7, Geronimo 2.2.1).