本文介绍了将jetty 7更新为jetty 8:java.lang.NoClassDefFoundError:javax / servlet / FilterRegistration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图通过嵌入jetty来开发Web服务器。所以对于jetty 7.3一切正常。昨天我将jetty库更新到了最新版本8.0.3,现在我通过创建ServletContextHandler得到了一个Exception。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.所以我所做的是: 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(); }}所以行抛出异常是:ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);我使用ubuntu 11.04:Im using ubuntu 11.04 with: openjdk java version1.6.0_22 OpenJDK Runtime Environment(IcedTea6 1.10.2)(6b22-1.10.2-0ubuntu1~11.04.1) OpenJDK 64位服务器VM(版本20.0-b11,混合模式)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)有没有人有建议?推荐答案 javax.servlet.FilterRegistration 类。此异常表明您在运行时类路径中仍然存在较旧的Servlet API版本的库,这些库在类加载中具有优先权。例如,从Internet上随机选择 / WEB-INF / lib 文件夹中的 servlet-api.jar 文件webapp或者可能在JRE的 / lib 文件夹中。您应该删除那些位于类路径中的其他位置的servletcontainer特定库,而不是目标运行时本身。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.如果你这样做是为了规避编译问题,那么你应该在类路径中使用目标运行时库。在Eclipse中,您可以在项目属性的 Target Runtime 部分中执行此操作。另请参见如何做我在Eclipse项目中导入javax.servlet API?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? 这篇关于将jetty 7更新为jetty 8:java.lang.NoClassDefFoundError:javax / servlet / FilterRegistration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-27 12:21