How to find dependency libraries to add to your Maven POM


This handy technique can help you figure out how to declare dependencies for common libraries in your Maven 2 POM.

Before Maven, getting a common library like log4j meant browsing to the Apache website and downloading the latest binary. Now, with Maven, we don't have to scurry around the web collecting various library dependencies; we can simply specify the dependency in our Maven POM and the let the Maven system do the rest.

But sometimes, it is not easy to know how to define the library dependency in the POM. One technique I like to use is just to browse the Maven 2 Repository directly by pointing my web browser to the following URL:

Suppose we would like to add the latest log4j library to our POM, for example. I can simply browse the Maven 2 repository index and click on the link for log4j. Once in that area, I can easily see the latest version available. Here's the listing I get:

1.1.3/                                             04-Jan-2007 19:21                   -
1.2.11/                                            04-Jan-2007 19:21                   -
1.2.12/                                            04-Jan-2007 19:21                   -
1.2.13/                                            04-Jan-2007 19:21                   -
1.2.14/                                            08-Jan-2007 15:56                   -
1.2.15/                                            30-Aug-2007 17:41                   -
1.2.4/                                             04-Jan-2007 19:21                   -
1.2.5/                                             04-Jan-2007 19:21                   -
1.2.6/                                             04-Jan-2007 19:21                   -
1.2.7/                                             04-Jan-2007 19:21                   -
1.2.8/                                             04-Jan-2007 19:21                   -
1.2.9/                                             04-Jan-2007 19:21                   -
maven-metadata.xml                                 03-Jan-2006 17:34                 484
maven-metadata.xml.md5                             04-Jan-2007 19:21                  67
maven-metadata.xml.sha1                            09-Jul-2006 13:41                 122

So, then I click on 1.2.15 (the latest version) to get the following listing:

log4j-1.2.15-sources.jar                           30-Aug-2007 17:41              389160
log4j-1.2.15-sources.jar.asc                       30-Aug-2007 17:41                 186
log4j-1.2.15-sources.jar.md5                       30-Aug-2007 17:41                  32
log4j-1.2.15-sources.jar.sha1                      30-Aug-2007 17:41                  40
log4j-1.2.15.jar                                   30-Aug-2007 17:41              391834
log4j-1.2.15.jar.asc                               30-Aug-2007 17:41                 186
log4j-1.2.15.jar.md5                               30-Aug-2007 17:41                  32
log4j-1.2.15.jar.sha1                              30-Aug-2007 17:41                  40
log4j-1.2.15.pom                                   30-Aug-2007 17:41               17780
log4j-1.2.15.pom.md5                               30-Aug-2007 17:41                  32
log4j-1.2.15.pom.sha1                              30-Aug-2007 17:41                  40
maven-metadata.xml                                 30-Aug-2007 17:41                 165
maven-metadata.xml.md5                             30-Aug-2007 17:41                 121
maven-metadata.xml.sha1                            30-Aug-2007 17:41                 129

And from here, I click on maven-metadata.xml to get the real information I need in order to declare the dependency in my POM:


I have the groupId, artifactId, and the latest version. So, I can declare the dependency in my POM as follows:


This handy technique can help you figure out how to declare dependencies for common libraries.

Unknown macro: {pop-layout}
Unknown macro: {portlet-a}