从 Jetty 6 迁移到 Jetty 8
我在简单的应用程序中使用 jetty6 作为嵌入式 servlet 容器。我决定将其更新到 Jetty 8。 在jetty 6中启动服务器非常简单:
Server server = new Server(8080);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(MyServlet.class, "/communication-service");
server.start();
但在Jetty8中不起作用。 不幸的是我找不到这个版本的任何简单的例子。无法实例化 Context 并出现错误,
an enclosing instance that contains
org.eclipse.jetty.server.handler.ContextHandler.Context is required
因为它现在是一个内部类,而且也没有这样的构造函数。
大多数示例针对 6 号和 7 号码头。 您能否提供如何在 jetty 8 启动 servlet 的简单示例?
I use jetty6 in simple application as embedded servlet container. I decided to update it to Jetty 8.
In jetty 6 it was pretty simple to start the server:
Server server = new Server(8080);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(MyServlet.class, "/communication-service");
server.start();
but it doesn't work in Jetty8.
Unfortunately I can't find any simple example for this version. Can't instantiate Context with error
an enclosing instance that contains
org.eclipse.jetty.server.handler.ContextHandler.Context is required
because now it is an inner class and also no such constructor.
Most examples are for jetty 6 and 7.
Could you please provide simple example how to start servlet at jetty 8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是与您的代码等效的 Jetty 8。它仍然像以前一样简单,但 API 略有变化。
如果这对您不起作用,那么您可能遇到了类路径问题 - Jetty 8 被分成许多独立的 jar 文件,您将需要其中许多文件。至少你需要:
如果你有这些 jar,那么这段代码应该可以正常工作:
This is the Jetty 8 equivalent to your code. It's still just as simple as it was before, however the API has changed slightly.
If this isn't working for you, then you probably have a classpath issue - Jetty 8 is separated into a lot of independent jar files, and you will need a number of them. At the very least you need:
If you have those jars, then this code should work fine:
Jetty 现在是 Eclipse 的一部分。文档此处适用于 Jetty 7,但声称它应该适用于 Jetty 8。有一个示例在页面末尾使用 servlet。
Jetty is nowadays part of Eclipse. The documentation here is for Jetty 7 but claims it should work for Jetty 8. There's an example of using servlets towards the end of the page.