Difference between javax.servlet-api.jar vs servlet-api.jar

javax.servlet-api version 3.0.1 has annotation folder which contains different annotation classes where servlet-api version 2.5 or below (i.e version 2.4) does not contain annotation.

Annotation represents the metadata. If you use annotation, deployment descriptor i.e. web.xml is not required. For example if you use annotation like @WebServlet("/hello") in your servlet file then you don't need to mention servlet mapping in web.xml file.

Some of useful Annotations are:

@HandlesTypes
@HttpConstraint 
@HttpMethodConstraint
@MultipartConfig
@ServletSecurity
@WebFilter
@WebInitParam
@WebListener
@WebServlet

You need to add

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

to your project. The version you need may differ - it depends on your servlet container, e.g. Tomcat.

<scope>provided</scope> because you don't need it in runtime, it's already in your servlet container.


Go with javax.servlet-api.jar , Many developers mistakenly include servlet-api.jar in their WEB-INF/lib folder. This no longer causes an exception because Tomcat and other app servers will recognize it as a problem when deploying the JAR file. However, it does cause the container to ignore any JAR file that contains the javax/servlet/Servlet.class.