Maven Dependency Mechanism, How It Works
来源:互联网 发布:数据的预处理包括哪些 编辑:程序博客网 时间:2024/05/30 12:30
转自:http://www.mkyong.com/maven/how-to-use-maven-dependency-to-download-library-automatically/
Maven’s dependency mechanism help to download all the necessary dependency libraries automatically, and maintain the version upgrade as well.
Case study
Let see a case study to understand how it works. Assume you want to use Log4J as your project logging mechanism. Here is what you do…
1. In traditional way
- Visit http://logging.apache.org/log4j/
- Download the Log4j jar library
- Copy jar to project classpath
- Include it into your project dependency manually
- All manages by yourself, you need to do everything
If there is a Log4j version upgrade, you need to repeat above steps again.
2. In Maven way
- You need to know the log4j
Maven coordinates
, for example<groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.14</version>
It will download the log4j version 1.2.14 library automatically. If the “version” tag is ignored, it will upgrade the library automatically when there is a newer version.
- Declares
Maven coordinates
intopom.xml
file.<dependencies> <dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.14</version> </dependency></dependencies>
- When Maven is compiling or building, the log4j jar will be downloaded automatically and put it into your Maven local repository.
- All manages by Maven.
Explanation
See the different? So what just happened in Maven? When you build a Maven’s project, the pom.xml
file will be parsed, if it see the log4j Maven coordinate, then Maven search the log4j library in this order :
- Search log4j in Maven local repository.
- Search log4j in Maven central repository.
- Search log4j in Maven remote repository (if defined in pom.xml).
This Maven dependency library management is a very nice tool, and save you a lot of work.
How to find the Maven coordinates?
Visit this Maven center repository, search the jar you want to download.
Reference
- Introduction to the Dependency Mechanism
- Maven Dependency Mechanism, How It Works
- How the Linux Kernel initcall Mechanism Works
- Selenium Grid How it Works
- How It Works -- Master Boot Record
- How It Works: SQL Server Page Allocations
- "Karma-How It Works"Karma怎么运行
- ADB-How it works---system-core-adb
- Angular 基础部分 1.4 How it Works
- EU4-62: Explaining how it works
- Project Butter - How It Works And What It Added
- UNIX® Load Average Part 1: How It Works
- Inside Qt Series (十五):Qt/e 输入法,How it works?
- How VSync works, and why people loathe it
- How VSync works, and why people loathe it
- Garbage Collection in .NET - How it really works
- Inside Qt Series (十五):Qt/e 输入法,How it works?
- What is Index and how it works in SQL Server?
- UNIX Load Average Part 1: How It Works
- MFC程序逆向 – 消息篇(下)
- Merge Into 语法
- php笔记(1)简单留言板
- spring mvc简单demo
- 由jQuery的幻灯图片引发的思考
- Maven Dependency Mechanism, How It Works
- 【原】Oracle 如何修改列的数据类型
- -all_load -force_load -ObjC使用解释
- 用OpenSceneGraph实现的NeHe OpenGL教程 - 第四十四课
- 篮球最强队伍与马尔科夫模型
- STC89C52RC数码管秒表程序编写
- Makefile之介绍
- Etherlords II ESO Gold kaufen m
- YUM常用命令介绍