how to add the servlet api to my pom.xml
65,527
Solution 1
I believe most web/app servers come bundled with a version of the servlet api, so you won't want to bundle the api in your .war file. You will need to find out which version is included with your server, then you can use
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-version}</version>
<scope>provided</scope>
</dependency>
replacing servlet-api-version with your version. You will want to specify the "provided" scope so the api.jar isn't included in your war file.
Solution 2
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Solution 3
For servlet-api 3.1.0, here is the declaration :
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Solution 4
We use
<dependency>
<groupId>javax</groupId>
<artifactId>j2ee</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
but if you only need the servlet api you might want to use
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>?</version>
<scope>provided</scope>
</dependency>
Author by
flybywire
Updated on February 20, 2022Comments
-
flybywire about 2 years
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?
-
Neil almost 11 yearsyou have to add the servlet-api-version in the properties tag also ?
-
digitaljoel almost 11 yearspreferably, yes, or you could just put the version directly in the version tag if you prefer.
-
Adam about 8 yearsOn mvnrepository on the entry for
javax.servlet:servlet-api:3.0-alpha-1
someone has written (and I have no idea who): Note: This artifact was moved to: New Group javax.servlet New Artifact javax.servlet-api . So the seemingly more correctjavax.servlet:servlet-api
is not actually the correct one. -
John over 7 yearsAwesome, thanks, still begs the question, how did you know? Kindly share the maven-fu :)