Question

I am trying to use the GZipFilter servlet provided in the jetty-servlets lib. My web app runs on Tomcat rather than Jetty. I know that Jetty is another servlet engine, but I should be able to use individual components.

I use maven to build my application. Whenever I include jetty-servlets in my pom, my web application refuses to start, failing at the declaration of GzipFilter in the web.xml.

The error is as follows,

Mar 31, 2014 3:03:32 PM org.apache.catalina.core.StandardContext filterStart SEVERE: Exception starting filter GzipFilter java.lang.NoClassDefFoundError: javax/servlet/AsyncListener at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493) at java.lang.Class.getConstructor0(Class.java:2803) at java.lang.Class.newInstance(Class.java:345) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)

I knew that Jetty-Servlets has a dependency on servlets-api, so I excluded it from the dependency in maven.

My snippet of pom.xml looks like,

<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlets</artifactId> <version>9.1.0.M0</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </exclusion> </exclusions> </dependency>

My snippet of web.xml looks like,

<filter> <filter-name>GzipFilter</filter-name> <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class> <init-param> <param-name>mimeTypes</param-name> <param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml</param-value> </init-param> </filter> <filter-mapping> <filter-name>GzipFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

Was it helpful?

Solution

The missing javax.servlet.AsyncListener class is part of Servlet Spec 3.0, which makes sense because Jetty 9.0.x follows that spec. Perhaps you are using an older version of Tomcat? Tomcat versions prior to 7.0.x do not implement this, in which case you have a problem.

See also this question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top