Maven by Example
   - 4.5. Add New Dependencies

4.5. Add New Dependencies

The Simple Weather application is going to have to complete the following three tasks: retrieve XML data from Yahoo Weather, parse the XML from Yahoo, and then print formatted output to standard output. To accomplish these tasks, we have to introduce some new dependencies to our project’s pom.xml. To parse the XML response from Yahoo, we’re going to be using Dom4J and Jaxen, to format the output of this command-line program we are going to be using Velocity, and we will also need to add a dependency for Log4J which we will be using for logging. After we add these dependencies, our dependencies element will look like the following example.

Adding Dom4J, Jaxen, Velocity, and Log4J as Dependencies. 


As you can see above, we’ve added four more dependency elements in addition to the existing element which was referencing the test scoped dependency on JUnit. If you add these dependencies to the project’s pom.xml file and then run mvn install, you will see Maven downloading all of these dependencies and other transitive dependencies to your local Maven repository.

How did we find these dependencies? Did we just “know” the appropriate groupId and artifactId values? Some of the dependencies are so widely used (like Log4J) that you’ll just remember what the groupId and artifactId are every time you need to use them. Velocity, Dom4J, and Jaxen were all located using the searching capability on This is a public Sonatype Nexus instance which provides a search interface to various public Maven repositories, you can use it to search for dependencies. To test this for yourself, load and search for some commonly used libraries such as Hibernate or the Spring Framework. When you search for an artifact on this site, it will show you an artifactId and all of the versions known to the central Maven repository. Clicking on the details for a specific version will load a page that contains the dependency element you’ll need to copy and paste into your own project’s pom.xml. If you need to find a dependency, you’ll want to check out, as you’ll often find that certain libraries have more than one groupId. With this tool, you can make sense of the Maven repository.

Become a Member

Are you a current user of: