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>
Share:
65,527
flybywire
Author by

flybywire

Updated on February 20, 2022

Comments

  • flybywire
    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
    Neil almost 11 years
    you have to add the servlet-api-version in the properties tag also ?
  • digitaljoel
    digitaljoel almost 11 years
    preferably, yes, or you could just put the version directly in the version tag if you prefer.
  • Adam
    Adam about 8 years
    On 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 correct javax.servlet:servlet-api is not actually the correct one.
  • John
    John over 7 years
    Awesome, thanks, still begs the question, how did you know? Kindly share the maven-fu :)