Search code examples
jakarta-eejbossjboss7.xresteasyweb.xml

Resteasy: java.lang.NoClassDefFoundError: javax/servlet/ServletContext


I have Resteasy servlet and listener configured in web.xml

<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<!-- Auto scan REST service -->
<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>

<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
</listener>

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>

When I trying to deploy EAR on JBoss-as-web-7.0.0.Final I get error:

org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NoClassDefFoundError: javax/servlet/ServletContext

My EAR contains war and EJB jar inside, if it have a meaning.


Solution

  • 1) you need to servlet api dependency in your project as below:

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    

    OR

    add javax.servlet-3.0.jar file in your classpath.

    2) 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>`
    

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

    I recommend you to use Jboss AS 7.1.1.Final version only instead of 7.0.0 Final.