views:

736

answers:

4

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?

A: 

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.

Vineet Reynolds
A: 

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>
Michael Rutherfurd
+5  A: 

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.

digitaljoel
Good point, I forgot to mention that
Michael Rutherfurd
perhaps I should have clarified on your answer instead of providing my own. Sorry about that.
digitaljoel
A: 

You can get them from sun

Add this

   <repositories>
        <repository>
          <id>maven2-repository.dev.java.net</id>
          <name>Java.net Repository for Maven</name>
          <url>http://download.java.net/maven/2/&lt;/url&gt;
          <layout>default</layout>
        </repository>
      </repositories>

Then look here for the artifact ids.

sal