Search code examples
asynchronousjax-rsgradleresteasyjetty-8

Gradle issue - Trying to do some JAX-RS 2 with Jetty and Resteasy - ClassNotFoundException: javax.servlet.AsyncListener


I use:

  • Jetty 8.1.11
  • Resteasy 3.0.1.Final
  • Gradle 1.6 - jettyRun task - Running on windows 7 -> This is the culprit

Update: If I deploy my war directly in Jetty, it works fine, but if I start with the gradle jettyRun task, it fails. so it is related to Gradle

I get this stack:

java.lang.NoClassDefFoundError: javax/servlet/AsyncListener
    at org.jboss.resteasy.plugins.server.servlet.Servlet3AsyncHttpRequest.<init>(Servlet3AsyncHttpRequest.java:38)
    at org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher.createHttpRequest(HttpServlet30Dispatcher.java:24)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.createResteasyHttpRequest(HttpServletDispatcher.java:61)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:210)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)

And my gradle:

apply plugin: 'war'

apply plugin: 'jetty'

apply plugin: 'idea'


sourceCompatibility = 1.7
targetCompatibility = 1.7

def springVersion = "3.2.3.RELEASE"
def jaxrsVersion = "2.0"
def resteasyVersion = "3.0.1.Final"

group = 'com.test'
version = '1.0-SNAPSHOT'

...

dependencies {

    compile "org.jboss.resteasy:resteasy-jaxrs:$resteasyVersion"
    compile "org.jboss.resteasy:async-http-servlet-3.0:$resteasyVersion"
}

Web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <display-name>Archetype RestEasy Web Application</display-name>
       <context-param>
           <param-name>resteasy.servlet.mapping.prefix</param-name>
           <param-value>/chat</param-value>
       </context-param>

       <servlet>
           <servlet-name>Resteasy</servlet-name>
           <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher</servlet-class>
           <init-param>
               <param-name>javax.ws.rs.Application</param-name>
               <param-value>com.test.MovieManApiApplication</param-value>
           </init-param>
       </servlet>

       <servlet-mapping>
           <servlet-name>Resteasy</servlet-name>
           <url-pattern>/chat/*</url-pattern>
       </servlet-mapping>

</web-app>

I don't see what is missing and dit not find anything really related on the net.

Thank you


Solution

  • Gradle's Jetty plugin is based on Jetty 6, which doesn't support Servlet 3.0. You may want to look into the Arquillian Gradle plugin or Gradle Cargo plugin instead.