Updating jetty 7 to jetty 8 : java.lang.NoClassDefFoundError: javax/servlet/FilterRegistration
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?
sockeqwe
Updated on June 13, 2022Comments
-
sockeqwe about 2 years
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.(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 do is:
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 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?
-
sockeqwe over 12 yearsthank you for your answere, but im still wondering where the Servlet 3.0 API is available to download? Does the Java SE JDK 1.6 update 22 (openjdk) not provide Servlet 3.0? Im confused ...
-
BalusC over 12 yearsYou've already downloaded it. Jetty 8 is a Servlet 3.0 API implementation. You only need to grasp that the Java EE API's are abstract (i.e. they exist in paper only as specs and javadocs) and that the concrete Java EE / Servlet containers like Jetty, Tomcat, Glassfish, JBoss AS etc..etc.. are the concrete implementations (i.e. they contain the code and libraries).
-
sockeqwe over 12 yearsOk, it was my error in reasoning. I have included all jetty libaries, but the exception is still there
-
BalusC over 12 yearsYou're not the only and the first :) See also among others stackoverflow.com/questions/165230/… and stackoverflow.com/questions/7295096/what-exactly-is-java-ee/….
-
BalusC over 12 yearsIf you still have the exception then it means that you don't have included libraries of a Servlet 3.0 compatible implementation, or that you still have libraries of a older servlet version somewhere in the runtime classpath. Jetty 8 is (should be) Servlet 3.0 compatible (otherwise it would be a major bug in Jetty 8), so it's still the 2nd possible cause. Walk through all the paths covered by the runtime classpath once again to get rid of container-specific libraries of a different container like
servlet-api.jar
,javaee.jar
and so on. Or maybe you've still Jetty 7 libs in the classpath? -
sockeqwe over 12 yearsIm using GWT 2.3 to build the client, but i do no use GWT on server side (no RPC, no app engine etc.). Do you think that this could be the reason for my problem, since there is in the WEB-INF/lib folder the gwt-servelet.jar ? So what i want to develop is an Simple Client using GWT and an own (web)server by embedding jetty and to use WebSockets for the communication between server and client.
-
BalusC over 12 yearsI don't do GWT, but last what I know is that it doesn't support Servlet 3.0 yet, so that library could be very good the reason. Check it with a ZIP tool, you'll see that the class in question is missing in there (as all other Servlet 3.0 specific classes/methods). I also wonder if that library is necessary as you seem to not use GWT on server side, so you should be able to just remove it.
-
sockeqwe over 12 yearshm, ok, thank you for your great help! I can't see any reason, why does GWT should have some impact on my own implemented server. My server is a "simple" java application and has nothing to do with GWT ... Maybe it would be easier if I use jetty 7
-
BalusC over 12 yearsYou could also just remove the offending library as you don't seem to use it.
-
sockeqwe over 12 yearsok, i did it, but now i face another exception, that seems that is caused by other GWT dependancy to each other: java.lang.SecurityException: class "javax.servlet.FilterRegistration"'s signer information does not match signer information of other classes in the same package ... ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
-
BalusC over 12 yearsI'm afraid that there's no other way than to forget GWT or to fall back to Servlet 2.5 / Jetty 7 until they upgraded GWT to be Servlet 3.0 compatible.
-
sockeqwe over 12 yearsThank you very much for your help!
-
Rohit Verma almost 7 yearsIn my case, servlet-api:2.5 was inherited from hbase client. used "gradle dependencies" command to locate the same.