Parsing a Maven POM II

Due to popular demand here is the code that does the parsing described in this article some time ago:

It’s just a quick hack but it works fine for all projects at – The dependency information as on this page is actually parsed using the above Maven Pom Reader.

Here is a short example how to use it:

// Path to your local Maven repository
final File repositoryDir = new File("/data/maven/repository");

// Read the model for an artifact and a given version
final Model model = MavenPomReader.readModel(repositoryDir, "org.fuin", "serialver4j", "0.4.2");

// Print the dependencies on the console
final List<Dependency> dependencies = model.getDependencies();
for (int i = 0; i < dependencies.size(); i++) {
    final Dependency dependency = dependencies.get(i);
    System.out.println(dependency.getGroupId() + " / " + dependency.getArtifactId() + " / "
        + dependency.getVersion() + " / " + dependency.getScope());


com.thoughtworks.xstream / xstream / 1.3.1 / null
com.caucho / hessian / 3.1.5 / null
org.reflections / reflections / 0.9.5-RC2 / null
junit / junit / 4.8.1 / test
org.easytesting / fest-assert / 1.3 / test
org.fuin / units4j / 0.2.3 / test
org.fuin / utils4j / 0.6.7 / test


4 thoughts on “Parsing a Maven POM II

  1. I was looking for something like this and stumbled on to this site. Great example but I am having some trouble with the dependencies. Tried to use the ones listed on your link but even though I add your repositories and dependencies, Utils4J cannot be resolved. Could I perhaps take a look at your pom.xml?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s