【问题标题】:Embedded Jetty is running with old version of servlets APIEmbedded Jetty 使用旧版本的 servlets API 运行
【发布时间】:2015-07-01 01:13:27
【问题描述】:

我的嵌入式 Jetty 在/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"/>

我使用以下代码启动我的服务器:

    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();

我的目的是使用 Servlet API 3.0 运行。当我只编译项目的 Jetty 部分时,它工作正常。但是,当我添加一个使用旧版本 Jetty(Hadoop 核心)的外部库时,我的嵌入式 Jetty 服务器降级到 2.5 并在 HttpRequest#getParts 调用上抛出 NoSuchMethodError。如何强制我的 Jetty 服务器使用 Java Servlets 3.0 运行?

我正在使用 Jetty 8.1.16.v20140903。

【问题讨论】:

    标签: java servlets jetty


    【解决方案1】:

    如果使用构建工具,请从 hadoop 依赖项中排除 jetty 和 servlet-api 片段。

    只需确保您没有使用旧版本的 Jetty。

    【讨论】:

    • 差不多就是这样
    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 2013-07-13
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2012-03-23
    相关资源
    最近更新 更多