设置 Jetty 服务器

Setting up Jetty server

我使用带有 xml 配置的 jetty-server 和 jetty-webapp 包,但它显示错误: "Exception in thread "主要" java.lang.ClassNotFoundException: org.eclipse.jetty.server.nio.SelectChannelConnector"

这个错误是怎么来的?

如果注释这部分xml配置:

<Call name="addConnector">
    <Arg>
        <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="port">8080</Set>
            <Set name="host">88.147.197.118</Set>
        </New>
    </Arg>
</Call>

然后 web-app 启动没有任何错误。

安装包版本为9.4.9.v20180320

SelectChannelConnector alternative class in Jetty 9 and above

这个class好像不能用于Jetty 9及以上版本。请改用 ServerConnector

org.eclipse.jetty.server.nio.SelectChannelConnector来自Jetty7.x和8.x时间段。 Long ago deprecated and EOL.

Jetty 中的连接器基础结构 9.x 从那时起发生了巨大变化。 主要是由于 SPDY 和 HTTP/2(以及 TLS/1.2 和 ALPN)的压力。

在 Whosebug 的回答中描述整个新的连接器架构超出了范围。

但如果您只是在寻找示例,我建议您下载 jetty-home 工件,或 jetty-distribution 工件并查看 /etc/*.xml 文件以获取示例。

查看:

  • jetty-http.xml - 用于正常的 HTTP 连接器设置(仅 HTTP/1.x)
  • jetty-https.xml - 用于普通 HTTPS (SSL/TLS) 连接器(仅 HTTP/1.x)
  • jetty-http2.xml - 对于典型的基于 HTTP/2 的连接器,退避到 HTTP/1.1
  • jetty-ssl.xml - 如何为 HTTPS 配置 SSL 层