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
- Visit http://logging.apache.org/log4j/
- Download the jar library for Log4 J
- Copy jar to project Classpath
- To manually include it in the project's dependencies
- 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
- You need to know the Maven coordinates of LOG4J, for example:
<groupid>log4j</groupid><artifactid>log4j</artifactid><version>1.2.14</ Version>
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.
- 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>
- When Maven compiles or builds, the log4j jar is automatically downloaded and put into the MAVEN local repository
- 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:
- Search log4j in Maven's local warehouse
- Search log4j in the Maven central repository
- 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
- 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