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>