Home » Enterprise Java » Maven » Maven Resolve Missing Artifact Error Example

About Neha Goel

Neha Goel
Neha holds a Bachelors degree in Computer Science and Engineering. Currently she is working as a Sr. Programmer Analyst for a client in USA and has a total of 9+ years of Java/J2EE experience.Her expertise includes participation in all stages of SDLC. She has experience with multiple web based and enterprise based applications. She has a very impressive understanding in Object oriented architecture, analysis, design and software development using latest technologies like Java, J2EE , Restful Services, Spring, Hibernate, JDBC, JSP, Servlets, GWT, ATG etc.

Maven Resolve Missing Artifact Error Example

In this example, we will be discussing about how to resolve “Missing Artifact” error while using Maven. Before we start with this article, it is expected that we have a basic understanding of how software development works with Java. It would also be good if we have an exposure to software build and deployment process to understand the usage and the working of the Apache Maven better. To get familiar with the installation, the usage and the basics of Maven please refer to the article Maven Hello World.

In this example, we will see how to resolve “Missing artifact error” while working with Maven.

Want to master Maven?

Subscribe to our newsletter and download the Apache Maven Cookbook right now!

In order to get you prepared for your Maven development needs, we have compiled numerous recipes to help you kick-start your projects. Besides reading them online you may download the eBook in PDF format!

 

1. Introduction

In general software terms, an artifact is something produced by the software development process, whether it is software related documentation or an executable file.

In Maven terminology, an artifact is a file, usually a JAR, that gets deployed to a Maven repository. It is a resource generated by a maven project. Each maven project can have exactly one artifact like a jar, war, ear, etc. Each artifact has a group ID (usually a reversed domain name, like com.jcg.maven), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact. You can refer to the pom.xml below.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.jcg.maven</groupId>
 <artifactId>MavenHelloWorldProject</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>MavenHelloWorldProject</name>
 <url>http://maven.apache.org</url>
 <dependencies>
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>3.8.1</version>
 <scope>test</scope>
 </dependency>
 </dependencies>
</project>

2. Missing Artifact error

Maven artifacts are not limited to java resources. We can generate whatever resource we need like, documentation, project-site, zip-archives, native-libraries, etc.

Each maven project has a unique identifier consisting of [groupId, artifactId, version]. When a maven project requires resources of another project a dependency is configured in it’s pom.xml using the [groupId, artifactId, version] identifier. Maven then automatically resolves the dependencies when a build is triggered. The artifacts of the required projects are then loaded either from the local repository, which is a simple directory in user’s home, or from other (remote) repositories specified in the projects pom.xml.

Maven throws “Missing artifact error” when a dependency is not recognized or a dependency artifact cannot be found either in the local repository or the remote repository depending on how we have configured our project to get the dependencies (check the <url> tag in pom.xml which helps to determine where maven will refer the dependencies). It may also means that Maven is not able to download the artifacts specified in the pom.xml from the repository.

3. Resolving Missing Artifact error

Whenever we get a missing artifact error while building our Maven project, the only thing we should first try out is to check for dependencies in the pom.xml.

Things that can be checked in pom.xml:

  1. Check if the correct repository is specified in the pom.xml from which the package was downloaded originally. It might happen that the url in pom.xml is not correct and you have the required jar file in the .m2 repository.
  2. Check for the artifact version, if the version specified in the pom.xml is there in the repository from where it should be downloaded.
  3. Check if the jar is missing or not. If yes, place it manually in the .m2 repository. Sometimes the jar mentioned in the pom.xml is not downloaded and it gives error.
  4. You can also try deleting the entire .m2 repository folder and run the maven build. The jars get downloaded from scratch. It might resolve the problem as well.
  5. In eclipse, you can always try to clean the project by selecting the Project->Clean option. There are a few other options apart from Project->Clean, some of which are more along the lines of turning it off and on again.
    • Try right-clicking on the project and select Maven->Update Project.
    • Disable then re-enable dependency management (right-click Maven->Disable Maven Nature then to again convert the project to a Maven project, Right Click on the project and select Configure ->Convert To Maven Project. Please refer to the screen shots below.
    • Close the project and reopen it.

Fig 1: Disable Maven Nature

Fig 2: Convert To Maven Project

6. Check that your Maven settings are configured correctly. If you are behind a proxy you’ll need to configure the proxy settings in the global or user settings.

7. You can also try right-clicking on the project and select Maven -> Update Project and check the option for “Force Update of Snapshot/Releases”. It will clean build the project checking for dependencies. Refer to the screenshot below.

Fig 3: Force Update of Snapshots

4. Conclusion

That was an example of the “Missing Artifact error” while building a Maven project. We saw some things that can be checked in order to resolve this error.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz