Date Created: Sat 24-Jan-2009

Related Document Categories:



    HttpServlet cannot be resolved to a type when adding a servlet using Eclipse.

    When trying to add a servlet using the Eclipse wizard you find the the generated code results in the compiler throwing an error "HttpServlet cannot be resolved to a type".

    The reason for this is the Eclipse will pick up your current JRE and the servlet api is not installed and referenced in your project because it is implemented by the application server vendors ie Tomcat, WebLogic and Websphere. What you can do is download the GlassFish Server ie Latest J2EE SDK + GlassFish from Sun to get the servlet-api.

    Download the latest J2EE version from Java. At the time of this writing it was GlassFish and SDK Update 7 found at http://java.sun.com/javaee/downloads/index.jsp.

    Download the J2EE version 7 and then you can refer to is as an installed JDK in your projects properties. Or you could download Tomcat and add an external jar to your project pointing to the servlet-api.jar file. If you had WebSphere installed you could use the j2ee.jar file from the WebSphere runtime and the equivalent for WebLogic of JBoss. Personally this is why I like IBM Rational Software Developer/Architect as it does all this for you when you create a Dynamic Web Project as it has automatici facet adding.

    Once you have added the JAR file Eclipse should automatically re-build and the error will go away.

Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories