Question

I am trying to add the javax.servlet-api project to my Maven Java project (see this link for more information about versions for this dependency). I want to add version 3.1.0 to my project. So naturally, I add this dependency to my pom.xml file:

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

However, when Maven tries to download the jar/pom files for this artifact, it gets an error because it automatically converts version 3.1.0 to 3.1, which is not its actual version, and it cannot find that version of the artifact in the central Maven repo:

Downloading: http://repo.maven.apache.org/maven2/javax/servlet/javax.servlet-api/3.1/javax.servlet-api-3.1.pom
[WARNING] The POM for javax.servlet:javax.servlet-api:jar:3.1 is missing, no dependency information available
Downloading: http://repo.maven.apache.org/maven2/javax/servlet/javax.servlet-api/3.1/javax.servlet-api-3.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal on project my-java-project: Could not resolve dependencies for project com.example.myproject:my-project:war:1.0-SNAPSHOT: Could not find artifact javax.servlet:javax.servlet-api:jar:3.1 in central (http://repo.maven.apache.org/maven2) -> [Help 1]

Does anyone know how I can tell Maven to not strip off trailing zeroes in the version tag of a dependency in my pom.xml file? Any other workaround known?

NOTE: I did check out this SOF post (Maven dependency for Servlet 3.0 API?), but this author's solution was to use a <scope>provided</scope> dependency for servlet-api, which I do not have interest in doing becuase I want to avoid needing to use the provided scope.

Was it helpful?

Solution

it gets an error because it automatically converts version 3.1.0 to 3.1

That is something impossible. Maven will never convert version numbers ( with the exception of snapshots ). It will always download the version that you specify in the pom.xml regardless the version actually exists or not. You can test this by writing a bogus number in the version area of the tag and then fire the mvn install command, you will see that it will try to download that version and then fail.

To debug your problem, first verify that you have the correct maven entry in the pom

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

Secondly , I would advise you to delete the folder ~/.m2/repository/javax/servlet/ to remove any bad jar and thus force maven to re-download all the javax.servlet jars

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