How to use Maven dependency to download library automatically
Maven’s dependency mechanism will download all the necessary dependency libraries automatically, and maintain the version upgrade as well.
Case study
Assume you want to use Log4J as your project logging mechanism (actually i more prefer SLF4J). Here is what you do…
In traditional way
1. Visit http://logging.apache.org/log4j/
2. Download the Log4j jar library
3. Manually include it into your project dependency
4. All manage by yourself
If there is Log4j version upgrade, you need to repeat the above steps again.
In Maven way
1. You need to know the 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 ignore, it will upgrade the library automatically where there is an update.
2. Include the “Maven coordinates” into “pom.xml” file, under “<dependencies>” tag
<dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> </dependencies>
3. While Maven is compiling or building, the log4j will download automatically and put it into your Maven local repository.
4. All manage by Maven… silently.
See the different? So what’s happened in Maven?
When you use Maven to build your project, “pom.xml” will be parsed, and the Maven work search the log4j library in the following location orderly :
1. Search log4j in Maven local repository.
2. Search log4j in Maven central repository.
3. Search log4j in Maven remote repository (if define in pom.xml).
The Maven dependency library management is quite impressive and handy ~ nice tool.
How to find the Maven coordinates?
The only problem is how to you know what is the library’s Maven coordinates? You can always refer to the Maven Central Repository for detail, or using this Google workaround – Use Google site search function



[...] Maven library dependency explanation Article about the different of dependency library in tradition way and Maven way, and explains where Maven will search those library. [...]