ClassNotFoundException:Jetty hello world 中的 javax.servlet.AsyncContext

发布于 2024-12-29 12:20:18 字数 504 浏览 0 评论 0原文

我正在尝试遵循 http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld 教程(蚀)。该项目编译良好。但是,当我点击本地主机服务器时,我得到:

java.lang.ClassNotFoundException: javax.servlet.AsyncContext

现在看起来是在 Java 中定义的EE 我需要在构建路径中添加什么才能使其正常工作?我已经安装了 Java EE,但我不知道从哪里开始。

我正在尝试使用

jetty-all-8.0.4.v20111024.jar

servlet-api-2.5.jar

I am trying to follow the http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld tutorial (with Eclipse). The project compiles fine. However, when I hit the localhost server I get:

java.lang.ClassNotFoundException: javax.servlet.AsyncContext

Now it looks like that is defined in Java EE what do I need to add to the build path to get this to work? I have installed Java EE but I am not sure where to go from there.

I am trying this with

jetty-all-8.0.4.v20111024.jar

servlet-api-2.5.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安人多梦 2025-01-05 12:20:18

该类是在 Servlet 3.0 中引入,它是Java EE 6。该教程中提到的 Jetty 7 是一个 Servlet 2.5 容器。 Servlet 2.5 是 Java EE 5 的一部分。您需要升级到 Jetty 8,它是 Servlet 3.0 容器。

下载并安装此处提供的整个 Java EE 包不会导致任何问题意义在于,这基本上为您提供了 Java EE 参考实现 Glassfish,而不是 Jetty,而您需要更新版本的 Jetty,而不是 Glassfish。

您还需要确保您没有从某个地方下载任意 servlet-api.jar 文件并将其放置在类路径中,而您已经拥有像 Jetty 这样的完整 servlet 容器(这是初学者为了避免在 javax.servlet API 上遇到的编译错误而犯的典型错误。

另请参阅:

That class is introduced in Servlet 3.0 which is part of Java EE 6. Jetty 7 as mentioned in that tutorial is a Servlet 2.5 container. Servlet 2.5 is part of Java EE 5. You need to upgrade to Jetty 8 which is a Servlet 3.0 container.

Downloading and installing the whole Java EE pack as available here makes no sense as that basically gives you the Java EE reference implementation Glassfish back, not Jetty, while you need a newer version of Jetty, not Glassfish.

You also need to make sure that you don't have downloaded an arbitrary servlet-api.jar file from somewhere and placed it in the classpath while you already have a fullworthy servlet container like Jetty at your hands (which is a classic beginner's mistake to circumvent compilation errors they faced on the javax.servlet API).

See also:

寂寞美少年 2025-01-05 12:20:18

我猜您安装了没有 AsyncContext 的 Java EE 5 。更新到 Java EE 6,其中包含:
Java EE 6 文档

I guess you installed Java EE 5 which has no AsyncContext. Update to Java EE 6 which has that:
Java EE 6 Doc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文