2

I added a dependency in maven for servlet as seen here, here and here

Maven doesn't find it :

dependency javax.servlet:javax.servlet-api:3.0.1 not found

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

I tried to add this, which doesn't work :

<repository>
    <id>maven2</id>
    <url>https://mvnrepository.com</url>
</repository>

or this:

<repository>
    <id>maven2</id>
    <url>http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/</url>
</repository>
Community
  • 1
  • 1
based
  • 65
  • 1
  • 7
  • I tried adding this dependency and it is working for me. check the error in your maven console and put it here. – Vijendra Kumar Kulhade Jun 02 '16 at 02:11
  • 1
    @VijendraKulhade what do you mean ? I'm using maven on intellij and the error intellij is giving me is : dependency javax.servlet:javax.servlet-api:3.0.1 not found. where can I check the maven error ? – based Jun 02 '16 at 02:17
  • Can you try adding maven repository in Intellij Idea settings. I have http://repo.maven.apache.org/maven2 added in my settings. If it is already there press update button. – Vijendra Kumar Kulhade Jun 02 '16 at 02:30
  • I had the same problem, then I noticed that I included a `//` comment instead of a `` comment in my pom.xml. IntelliJ didn't show that as the mistake but instead said that it couldn't find the dependency, which lead me on the wrong track :D – Boommeister Jul 09 '20 at 07:17

2 Answers2

4

First of all you need to verify if you have Internet connectivity and then you can try to purge and resolve the dependencies in the local Maven repository as there could be some corrupted package, you can try the following command to accomplish this:

mvn dependency:purge-local-repository

Take a look to Purging local repository dependencies for more information.

rea-al
  • 91
  • 4
  • 1
    @real-al thanks this worked. I'll upvote as well when I've enough points. When trying to purge I had an error message telling me that the version of plugin weren't correct (I put LATEST). Then after the purge it worked. – based Jun 02 '16 at 02:33
  • You shouldn't use `LATEST` as a version. Better pin the version with particular version you would like to use. – khmarbaise Jun 02 '16 at 06:33
3

Use default repostiory:

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

Don't do like this: http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/

Even you should remove all content of the tag <repositories> or <repository> and all things inside these, Maven will automatic use default configuration.


Reference: http://maven.apache.org/pom.html#The_Super_POM

Vy Do
  • 46,709
  • 59
  • 215
  • 313