ClassNotFoundException:Jetty hello world 中的 javax.servlet.AsyncContext
我正在尝试遵循 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该类是在 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 thejavax.servlet
API).See also:
我猜您安装了没有 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