Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 768
user833970 Avatar asked Jan 27 '12 17:01

user833970


1 Answers

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:

  • What exactly is Java EE?
  • How do I import the javax.servlet API in my Eclipse project?
like image 184
BalusC Avatar answered Oct 28 '22 21:10

BalusC