Maven Dependency and Repository

Source: Internet
Author: User

Let's look at one of the most common examples:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

This example shows that your project has a junit dependency. You might ask: Where does this dependency come from? Where is the JUnit jar?

A dependency is a reference to a artifact in the repository. The Pom defines a dependency, which is executed by the dependency GroupID, Artifactid and version, to search it from repository. You don't have to be in the Pom.xml to indicate which repository,maven the dependancy from will first find the local repository, if the local repository has dependancy that the artifact references, Use it, if not, search all the remote repository you set, and if you find it, download it to the local repository. By default, the artifact is usually download from the repository (HTTP://WWW.IBIBLIO.ORG/MAVEN2). If your pom.xml defines multiple remote repository, then try to download them from remote repository sequentially.

For example, MAVEN will check the local repository to see if there is a desired junit artifact, if not, from remote repository download to local repository. At this point, the artifact directory structure in the local repository contains:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.