sockeqwe sockeqwe - 2 years ago 305
Java Question

Updating jetty 7 to jetty 8 : java.lang.NoClassDefFoundError: javax/servlet/FilterRegistration

im trying to develop an web server by embedding jetty. So with jetty 7.3 everything worked fine. Yesterday I updated the jetty libaries to the newest version 8.0.3 and now I get an Exception by creating a ServletContextHandler.

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/FilterRegistration
at org.eclipse.jetty.servlet.ServletContextHandler.(
at org.eclipse.jetty.servlet.ServletContextHandler.(
at org.eclipse.jetty.servlet.ServletContextHandler.(
at org.gemsjax.server.GemsJaxServer.main(

So what I do is:

public static void main(String[] args) {

Server server = new Server(8080);

ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.addServlet(new ServletHolder( new CollaborationWebSocketServlet()),"/collaboration");

// The ResourceHandler to handle static web content
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setWelcomeFiles(new String[]{ "index.html" });


ContextHandler resourceContext = new ContextHandler();

HandlerCollection handlers = new HandlerCollection();



try {
} catch (Exception e) {


So the line that throw the exception is:

ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);

Im using ubuntu 11.04 with:

openjdk java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

Does anyone have a suggestion?

Answer Source

The javax.servlet.FilterRegistration class was introduced in Servlet 3.0. This exception suggests that you have still libraries of an older Servlet API version in your runtime classpath which got precedence in classloading. For example a randomly from the Internet picked servlet-api.jar file in /WEB-INF/lib folder of your webapp or perhaps in the JRE's /lib folder. You should remove those servletcontainer-specific libraries which are sitting somewhere else in the classpath than in the target runtime itself.

If you did this to circumvent compilation problems, then you should instead have taken the target runtime's libraries in the classpath. In for example Eclipse, you can do it in Target Runtime section of project's properties. See also How do I import the javax.servlet API in my Eclipse project?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download