Maven Learning---maven dependency mechanism

Source: Internet
Author: User
Tags maven central

Automatically download all required dependent libraries with the help of Maven dependency mechanism and keep the version upgrade.

Case analysis

Let's look at a case study to see how it works. Suppose you want to use log4j as the log for the project. What are you going to do here?

1. In the traditional way
    1. Visit http://logging.apache.org/log4j/
    2. Download the jar library for Log4 J
    3. Copy jar to project Classpath
    4. To manually include it in the project's dependencies
    5. All the management needs to be done by yourself

If you have a log4j version upgrade, you will need to repeat the previous steps.

2. In Maven's Way
    1. You need to know the Maven coordinates of LOG4J, for example:
      <groupid>log4j</groupid><artifactid>log4j</artifactid><version>1.2.14</ Version>
    2. It will automatically download the log4j 1.2.14 Repository. If the "version" label is ignored, it automatically upgrades the library when there is a new version.

    3. Declares that Maven coordinates are converted to pom.xml files.
      <dependencies>    <dependency><groupid>log4j</groupid><artifactid>log4j</ Artifactid><version>1.2.14</version>    </dependency></dependencies>
    4. When Maven compiles or builds, the log4j jar is automatically downloaded and put into the MAVEN local repository
    5. All managed by Maven
Explanatory notes

See what's different? So what exactly happened to maven? When building a MAVEN project, the Pom.xml file will be parsed, and if you see log4j maven coordinates, then maven searches the log4j library in this order:

    1. Search log4j in Maven's local warehouse
    2. Search log4j in the Maven central repository
    3. Search log4j in the Maven remote repository (if defined in Pom.xml)

Maven-dependent Library management is a great tool that saves you a lot of work.

How do I find Maven coordinates?
Visit the Maven central repository and search for the jar you want to download.

Reference
    1. Introduction to Dependency mechanisms


Tags: Maven dependency mechanism

This site is reproduced in addition to the article, are the original site or compiled
Welcome any form of reprint, but please be sure to indicate the source, respect for the work of others to create excellent examples of the tutorial
Reprint Please specify: Article reprinted from: http://www.yiibai.com/maven/maven-dependency-to-download-library.html

Maven Learning---maven dependency mechanism

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.