HTTPServlet not found: Add Server Runtime to Eclipse

If you create Java Web Projects, you will often receive:

javax.servlet.http.HttpServlet was not found on the Java Build Path.

This means that you miss a library with the specified class. The HttpServlet provides an abstract class to create an HTTP servlet for web applications.

1. Resolve the HttpServlet was not found Error

  1. The easiest (not recommended method) is adding the desired servlet jar into your class path manually.
    • Copy the required jar file into your library folder in the web application.
    • Right click the library in the project explorer and select Add to Build Path.
  2. If you use Maven you can add the following dependency to your pom.xml file; Be careful with the version and the target container. This is not recommended either, since you should use the servlet provided by your target container (e.g. Apache Tomcat).
  3. If you plan to use a servlet container like Apache Tomcat, continue reading.

2. Integrate Apache Tomcat into Eclipse

  1. Make sure you installed Apache Tomcat successfully. Check out this tutorial for detailed installation instructions.

    HTTPServlet not found in Build Path
    HTTPServlet not found in Build Path
  2. Now right click your Eclipse project and open the properties.
  3. Switch to Project Facets and select the Runtimes tab on the right hand side. Click New.
  4. Select the Apache Tomcat version you want to add (or another servlet runtime) and click Next.

    Eclipse New Server Runtime
    Select the Tomcat Version you want to use
  5. Add the Tomcat Installation Directory and click Finish. We use: E:\Developer\Tomcat\apache-tomcat-8.0.22.

    Eclipse New Server Runtime Path
    Add your Apache Tomcat directory
  6. Check your created Apache Tomcat Runtime and click Apply.

    Eclipse Project Facets
    Eclipse Project Facets
  7. Please check your Java Version and adapt it. You need:
    1. Minimum JDK 1.7 for Tomcat 8
    2. Minimum JDK 1.6 for Tomcat 7
    3. Minimum JDK 1.5 for Tomcat 6
  8. Now the Tomcat dependencies including the javax.servlet.http.HttpServlet class are added to your Build Path.

    Project Explorer Apache Tomcat Libraries
    Project Explorer with Apache Tomcat Libraries
  9. This should resolve the javax.servlet.http.HttpServlet Error.
Facebooktwittergoogle_plusredditpinterestlinkedinmail

One Thought to “HTTPServlet not found: Add Server Runtime to Eclipse”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.