ClassNotFoundException:Jetty hello world 中的 javax.servlet.AsyncContext [英] ClassNotFoundException: javax.servlet.AsyncContext in Jetty hello world
问题描述
我正在尝试遵循 http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld教程(使用 Eclipse).该项目编译良好.但是,当我访问 localhost 服务器时,我得到:
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
现在看起来是在 Java EE 中定义的,我该怎么办需要添加到构建路径才能使其工作?我已经安装了 Java EE,但我不知道从哪里开始.
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.
我正在尝试使用
jetty-all-8.0.4.v20111024.jar
jetty-all-8.0.4.v20111024.jar
servlet-api-2.5.jar
servlet-api-2.5.jar
推荐答案
那个类是 在 Servlet 3.0 中引入,它是 Java EE 6 的一部分.该教程中提到的 Jetty 7 是一个 Servlet 2.5 容器.Servlet 2.5 是 Java EE 5 的一部分.您需要升级到 Jetty 8,它是一个 Servlet 3.0 容器.
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.
下载并安装可用的整个 Java EE 包此处 没有意义,因为这基本上为您提供了 Java EE 参考实现 Glassfish,而不是 Jetty,而您需要更新版本的 Jetty,而不是 Glassfish.
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.
您还需要确保您没有从某处下载任意 servlet-api.jar
文件并将其放置在类路径中,而您已经拥有一个完整的 servlet 容器,例如 Jetty at你的手(这是一个典型的初学者错误,以规避他们在 javax.servlet
API 上遇到的编译错误).
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).
这篇关于ClassNotFoundException:Jetty hello world 中的 javax.servlet.AsyncContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!