7 Replies Latest reply on Mar 27, 2014 3:29 AM by Tuan Pham

    ClassNotFoundException: javax.servlet.ServletContextListener

    Shelley Baker Newbie

      Cross-post.

      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).

       

      Message was edited by: Shelley J. Baker. Added attachment.

        • 1. Re: ClassNotFoundException: javax.servlet.ServletContextListener
          jaikiran pai Master

          Shelley Baker wrote:

           

          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]

          The javax.* is being loaded from the module of that (plain) jar file. The javax.* module dependencies are added only to the jars which are deployments. Add a:

           

          Dependencies: javaee.api

           

          to the MANIFEST.MF of that jar.

          1 of 1 people found this helpful
          • 2. Re: ClassNotFoundException: javax.servlet.ServletContextListener
            Shelley Baker Newbie

            Thanks, but even after adding the javaee.api dependency to the ee-components-1.0.jar MANIFEST.MF, I get the same exception (java.lang.ClassNotFoundException: javax.servlet.ServletContextListener).

            Manifest-Version: 1.0
            Archiver-Version: Plexus Archiver
            Created-By: Apache Maven
            Built-By: SL010380
            Build-Jdk: 1.6.0_26
            Dependencies: javaee.api 
            
            
            • 3. Re: ClassNotFoundException: javax.servlet.ServletContextListener
              Shelley Baker Newbie

              I'm still having this problem, but thought I'd share a couple of my other attempts to resolve it. Since adding the javaee.api dependency to the manifest didn't work, I tried to resolve this by using the jboss-deployment-structure.xml file. I created this file at META-INF/jboss-deployment-structure.xml in my project's EAR. I tried a few similar attempts to add the javaee.api module to the deployment as follows:

              <jboss-deployment-structure>
                  <deployment>
                      <dependencies>
                          <module name="javaee.api" />
                      </dependencies>
                  </deployment>  
              </jboss-deployment-structure>
              

              The above attempt had no effect, resulting in the same exception: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener.

              <jboss-deployment-structure>
                  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
              </jboss-deployment-structure>
              

              The above attempt also had no effect, resulting in the same exception: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener.

              <jboss-deployment-structure>
                  <sub-deployment name="ee-components-1.0-SNAPSHOT.jar">
                      <dependencies>
                          <module name="javaee.api" />
                      </dependencies>
                  </sub-deployment>  
              </jboss-deployment-structure>
              

              This attempt resulted in a different exception, since the ee-components JAR is not actually considered a "sub-deployment" (despite the original exception which was thrown from Module "deployment.test-app.ear.ee-components-1.0-SNAPSHOT.jar:main"):

              14:25:45,269 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-13) MSC00001: Failed to start service jboss.deployment.unit."test-app.ear".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."test-app.ear".PARSE: Failed to process phase PARSE 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: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Sub deployment ee-components-1.0-SNAPSHOT.jar in jboss-structure.xml was not found. Available sub deployments: web-module.war, 
                   at org.jboss.as.server.deployment.module.DeploymentStructureDescriptorParser.subDeploymentNotFound(DeploymentStructureDescriptorParser.java:358)
                   at org.jboss.as.server.deployment.module.DeploymentStructureDescriptorParser.deploy(DeploymentStructureDescriptorParser.java:320)
                   at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)
                   ... 5 more
              

              As one additional attempt, though I didn't expect it to work, I added the javaee.api module dependency to the sub-deployment "web-module.war." As expected, I still got the ClassNotFoundException.

              I am relatively new to JBoss AS 7, but coming from other application servers, it is very surprising that my simple application does not have access to the servlet classes which I'd expect to be provided by the container, and based on the previous response and documentation, I'd think that declaring the javaee.api module as a dependency might at least allow me to workaround this problem, but I'm having no such luck. Any assistance would be greatly appreciated. Please let me know if my EAR file appears to violate a portable EAR file as defined by the spec (as far as I can tell, it seems inline with the EE specs). Regardless, I'd appreciate a better understanding of JBoss's proposed approach to workaround this issue, or thoughts on whether this might be a bug.

              • 4. Re: ClassNotFoundException: javax.servlet.ServletContextListener
                Anil Kumar Khichar Newbie

                Hi Shelley Baker,

                 

                I hope the foolowing step will get you resolved :

                 

                Go to <JBOSS-HOME>/standalone/configuration/standalone.xml

                 

                Find the element

                <subsystem xmlns="urn:jboss:domain:ee:1.0" />

                 

                and replace it by

                <subsystem xmlns="urn:jboss:domain:ee:1.0">

                      <global-modules>

                           <module name="javaee.api" slot="main"/>           

                      </global-modules>

                </subsystem>

                 

                It would definitely get you resolved. Please let me know your status.

                 

                Thanks!

                Anil

                • 5. Re: ClassNotFoundException: javax.servlet.ServletContextListener
                  varejao Newbie

                  The same problem happened here, with jboss eap 6.1 / eas 7.1. The problem was that my eclipse project was configured to use JavaSE, instead of JDK. I configured the build path accordingly and voilá! So, you should use JDK as the JRE Excecution Environment, compiler, etc.

                  • 6. Re: ClassNotFoundException: javax.servlet.ServletContextListener
                    Stefano Carfagna Newbie

                    Go to

                    JBoss\jboss-eap-6.1\modules\system\layers\base\javax\servlet\api\main

                     

                    include JAR

                    jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar

                     

                    For me it worked

                     

                    best regards

                    Stefano

                     

                    =================

                    stefano@data-ware.it

                    • 7. Re: ClassNotFoundException: javax.servlet.ServletContextListener
                      Tuan Pham Newbie

                      Hi, I've got nearly same problem like this and event I had either

                      <subsystem xmlns="urn:jboss:domain:ee:1.1">

                                <global-modules>

                                     <module name="javaee.api" slot="main"/>          

                                </global-modules>

                              </subsystem>

                      in standalone-full.xml and

                      jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1 in jboss-eap-6.1\modules\system\layers\base\javax\servlet\api\main

                      anyone tried this with the luck ?