how to add the servlet api to my pom.xml

Viewed 67404

How do I add the servlets API to my project's pom.xml

mvnrepository.com has lots of servlet api and similarly named projects, that I don't know which is the right one. Or are all of them ok?

7 Answers

Jakarta EE

In recent years, Oracle transferred the Java EE technologies to the Eclipse Foundation. There the technologies have been renamed to Jakarta EE. So Java Servlet is now known as Jakarta Servlet.

This name change was done to respect Oracle’s trademarks. Do a Web search to find many articles and videos discussing this transition.

This name change includes changing the package naming of the classes from javax.* to jakarta.*. This is a breaking change, though updating your project may be as simple as merely changing your import statements. But check that any libraries you depend on have versions available using the new naming as well.

Servlet 5

This transition has brought new versions of the Servlet specification. Version 5 of the spec is the same as Servlet 4 but with the new naming.

For the current version, edit your POM file to use the following Maven dependency. Check for updates in a Maven repository of your choice in the version numbering.

You can deploy web apps built with Servlet 5 to web containers such as Tomcat 10.0.x, Jetty 11.0.x, Glassfish 6, and several more.

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

Servlet 6

Jakarta Servlet 6 specification is currently in development, and will contain significant changes. The spec will be finalized later this year 2022.

See the overview page, the product page, project links page, and repository coordinates page.

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