Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
650 views
in Technique[技术] by (71.8m points)

jakarta ee - ClassNotFoundException: javax.servlet.AsyncContext in Jetty hello world

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...