Maven dependent mechanism

Outline

Automatically download all the necessary dependencies in Maven dependent mechanism of help, and keep the version upgrade. Let's look at a case study to learn how it works. Suppose you want to use Log4j as the logging project. What are you doing here?

The traditional way

  • Access http://logging.apache.org/log4j/
  • Download the Log4j jar library
  • Copy the jar to the project classpath
  • Manual to include it to rely project
  • The management needs to do everything all by themselves

If there Log4j version upgrade, you need to repeat the above steps once.

Maven way

  • You need to know Maven coordinates log4j, for example:

      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
  • It will automatically download the 1.2.17 version of log4j library
  • Statement Maven pom.xml file is converted into coordinates

      <dependencies>
          <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
          </dependency>
      </dependencies>
  • When Maven build or construct, log4j will automatically download the jar and put it in the local Maven repository
  • All managed by Maven

explain

See the difference? So in the end what happened in Maven? When creating a Maven project, pom.xml file will be parsed, if you see Maven coordinates log4j, and then Maven search log4j library in this order:

  • In the local repository search log4j Maven
  • In the Maven central repository search log4j
  • (If defined in pom.xml) in Maven remote repository search log4j

Maven dependencies management is a very good tool for you to save a lot of work

Guess you like

Origin www.cnblogs.com/bjio/p/11681942.html