Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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>

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>

It depends on which version of the servlet API you are using.

The javax.servlet artifact will provide jars for all of the servlet API versions.

Scope provided can be used when you dont want to put jar file inside the WEB-INF/lib folder instead you are supplying it at runtime either by container or JDK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top