简体   繁体   中英

Embedded Jetty is running with old version of servlets API

My embedded Jetty has the following file at /home/user/Desktop/jetty-web.xml :

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com
/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"/>

I start my server with the following code:

    Server server = new Server();

 SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(ServerConfig.PORT);
        connector.setMaxIdleTime(ServerConfig.MAX_IDLE_TIME);
        connector.setRequestHeaderSize(ServerConfig.REQUEST_HEADER_SIZE);
        server.setConnectors(new Connector[]{connector});

WebAppContext webAppContext = new WebAppContext();
webAppContext.setDescriptor("/home/user/Desktop/jetty-web.xml");
webAppContext.setBaseResource(Resource.newResource("/"));
        webAppContext.setContextPath("/");

//add a few servlets...

server.setHandler(webAppContext);

server.start();

My intention is to run with the Servlet API 3.0. When I compile just the Jetty part of my project this works fine. However, when I add an external library that uses an older version of Jetty(Hadoop core) my embedded Jetty server downgrades to 2.5 and throws a NoSuchMethodError on a HttpRequest#getParts call. How can I force my Jetty server to run with Java Servlets 3.0?

I'm using Jetty 8.1.16.v20140903.

If using a build tool, exclude jetty and the servlet-api pieces from the hadoop dependencies.

Simply be sure you don't use old versions of Jetty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM