Adding a Maven dependency to an Eclipse project

Reading time ~1 minute

Managing dependencies is one of the important task in developing a complex Java project. This normally includes searching for depending libraries and adding them to the Eclipse project. Sometime this is not a very pleasant task. But the good news is, Maven make it easy to handle dependencies in Java projects.

I wrote an article on creating an Eclipse project using Maven previously. This article is a follow-up on that.

Searching for dependency

Imagine that you want to use a particular Java class in you project and you want to find and include the corresponding Java library in your project. You can use http://search.maven.org to search for a Maven dependency. They have an advanced search which is very helpful if you only know the name of the required class.

Adding the dependency to Maven

From the results you get from the search identify the required library. By clicking on a version number in the search results you can get the dependency information for a artifact. Following is an example of Maven dependency snippet.

<dependencies>
  <dependency>
    <groupId>org.apache.synapse</groupId>
    <artifactId>synapse-core</artifactId>
    <version>2.1.0</version>
  </dependency>
  <!-- Add more dependencies if required -->
</dependencies>

Updating the eclipse project

Add this dependency information to pom.xml (I assume you already have and pom.xml in your project directory. If not add a pom.xml or read this post to know about creating an Eclipse project using Maven) and run following command to update the eclipse project.

mvn eclipse:eclipse

Alternatively you can also use an Eclipse plugin to handle Maven dependencies. An example for such a plugin is the m2eclipse plugin.

Online Pomodoro Timer

An Online Pomodoro Timer you can use to practice Pomodoro Technique Continue reading

Purging Git Branches

Published on October 12, 2015

Running Clustered Integration Tests in WSO2 MB

Published on October 05, 2015