9

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

user833970
  • 2,729
  • 3
  • 26
  • 41

2 Answers2

11

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • hmmm that might explain it I was just using the latest release of Jetty (8.0.4) and servlet-api(2.5). I'll try it with different versions and see if that works. – user833970 Jan 27 '12 at 18:53
  • You should not have loose `servlet-api.jar` files wandering around in classpath. Remove them all. A servlet container like Jetty provides it **already** by itself. Related food for reading: http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project – BalusC Jan 27 '12 at 18:58
  • yes, it works now. however the tutorial tells to download servlet-api.jar, and will not compile without it. – user833970 Jan 27 '12 at 19:00
  • Great. Not all tutorials are necessarily good. The best ones are Oracle's own ones. You basically need to reference Jetty's own libraries in compiletime classpath. – BalusC Jan 27 '12 at 19:01
0

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

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Sbhklr
  • 2,693
  • 1
  • 17
  • 20
  • thanks for the response. However, I downloaded Java EE 6 from http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-6u3-jdk-7u1-downloads-523391.html and restarted. Is there something I need to add to a class path somewhere? – user833970 Jan 27 '12 at 17:56