Jetty 7 upgrade to marina 8: java.lang.NoClassDefFoundError: javax / servlet / FilterRegistration

im trying to build a web server by embedding the marina. So with the berth 7.3 everything worked fine. Yesterday I updated the mail sheets to the latest version 8.0.3, and now I get an exception by creating a ServletContextHandler.

The exception in the "main" thread is java.lang.NoClassDefFoundError: javax / servlet / FilterRegistration on org.eclipse.jetty.servlet.ServletContextHandler. (ServletContextHandler.java:126) at org.eclipse.jetty.servlet.ServletContextHandler. (ServletContextHandler.java:106) at org.eclipse.jetty.servlet.ServletContextHandler. (ServletContextHandler.java:94) at org.gemsjax.server.GemsJaxServer.main (GemsJaxServer.java:38)

So what I am doing:

public static void main(String[] args) { Server server = new Server(8080); ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContext.setContextPath("/servlets"); servletContext.addServlet(new ServletHolder( new CollaborationWebSocketServlet()),"/collaboration"); // The ResourceHandler to handle static web content ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[]{ "index.html" }); resourceHandler.setResourceBase("./war/"); ContextHandler resourceContext = new ContextHandler(); resourceContext.setContextPath("/static"); resourceContext.setHandler(resourceHandler); HandlerCollection handlers = new HandlerCollection(); handlers.addHandler(resourceContext); handlers.addHandler(servletContext); server.setHandler(handlers); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } } 

So, the line that throws the exception:

 ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); 

Im using ubuntu 11.04 with:

openjdk java version "1.6.0_22" OpenJDK production environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1 ~ 11.04.1) 64-bit server version of OpenJDK (build 20.0-b11, mixed mode)

Does anyone have a suggestion?

+7
source share
2 answers

The javax.servlet.FilterRegistration class was introduced in Servlet 3.0. This exception indicates that you still have libraries of an older version of the Servlet API in your path to the execution classes that took precedence when loading classes. For example, I accidentally selected the servlet-api.jar file from the Internet in the /WEB-INF/lib folder of your web application or, possibly, in the JRE /lib folder. You must remove the libraries that are associated with the servlet container that are somewhere else in the classpath than in the target environment itself.

If you did this to get around compilation problems, you should use the target runtime libraries in the classpath instead. For example, in Eclipse, you can do this in the "Target runtime" section of the project properties. See Also How to import javax.servlet API into an Eclipse project?

+10
source

When you use SBT, the FilterRegistration class is present in version 3.0, and also if you use JETTY or Java 8, this JAR 2.5 automatically adds as a dependency,

Fix: Servlet-api-2.5 JAR was a mess there, I solved this problem by adding dependencies to servlets-api-3.0 jar,

enter image description here

0
source

All Articles