How to Resolve Exception HttpServlet cannot be resolved to a type – servlet-api.jar Maven Dependency

Last updated
App Shah
Crunchify » Java and J2EE Tutorials » How to Resolve Exception HttpServlet cannot be resolved to a type – servlet-api.jar Maven Dependency

HttpServlet cannot be resolved to a type - Crunchify

Are you getting “HttpServlet cannot be resolved to a type” while running your java program while starting Tomcat Server? Yes, I’m referring to this project: https://crunchify.com/how-to-run-java-program-automatically-on-tomcat-startup/

But you may see above mentioned exception while running this program.

You need to add the Servlet API to your classpath. In Tomcat 6.0, this is in a JAR called servlet-api.jar in Tomcat’s lib folder. You can either add a reference to that JAR to the project’s classpath, or put a copy of the JAR in your Eclipse project and add it to the classpath from there.

If you want to leave the JAR in Tomcat’s lib folder:

  • Right-click the project, click Properties.
  • Choose Java Build Path.
  • Click Add External JARs…
  • Browse to find servlet-api.jar and select it.
  • Click OK to update the build path.

Add External Jar - Crunchify Apache Tomcat Tutorial

Add Servelet-api.jar file - Apache Tomcat - Crunchify Tips

Or, if you copy the JAR into your project:

  • Right-click the project, click Properties.
  • Choose Java Build Path.
  • Click Add JARs…
  • Find servlet-api.jar in your project and select it.
  • Click OK to update the build path.

If you have a Maven Project then add below dependency:

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>servlet-api</artifactId>
	<version>2.5</version>
</dependency>

6 thoughts on “How to Resolve Exception HttpServlet cannot be resolved to a type – servlet-api.jar Maven Dependency”

  1. Thanks for the post, guys. Will much more ease my
    work and save my time and self-control. Because this can irritate
    sometimes, you know. Amazing screenshots and quotes. Hope it will work
    properly too and there won’t be HttpServlet cannot be resolved to a type.

    Reply

Leave a Comment