[Solved] The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path in Eclipse

1. Problem

If you are facing this error after importing an existing maven project into your eclipse IDE, then it means that http-servlet is not available in the project’s classpath and you must include it.

The error looks like this.

Java Build Path Error
Java Build Path Error

2. Solution

To include http-servlet into your classpath, you have two options.

1. Add Target Server Runtime

In this solution, you can add desired server runtime into your application as a project facet. As runtime servers have already servlet runtime dependencies, they get included in your project and hence the error is gone.

Update Project Runtime

2. Add Maven Dependency

Another option is to include the latest version of javax.servlet-api dependency from Maven repository. This will also fix the error.

Do not forget to run mvn update command after including the dependencies.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>

If you are using Jakarta servlet API, then you should be using the latest version of jakarta.servlet-api.

<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>6.0.0</version>
    <scope>provided</scope>
</dependency>

Happy Learning !!

Comments

Subscribe
Notify of
guest
23 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode