# Maven dependecies in Eclipse

## December 12, 2013

Not having worked with Java on a large-scale project before, I had also never touched Maven. (In this case, by large-scale project, I mean a project with lots of dependencies and a more involved build process - I did write a rather complex 3D renderer, but it only had a handful of dependencies that never changed and it was a traditional "hit f11 to run" application).

Apache Maven is a tool used for, well, a lot of things. It works with Java, C# and a bunch of other languages and automagically manages your dependencies and build process. It's essentially Ant's bigger brother.

When looking to add an existing library as a dependency to a project, it's very often to see it offered as a maven artifact. It would look something like this:

<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.7.22</version>
</dependency>

This can be a tad frustrating if you're in a hurry and you just want to download a jar to add to your build path. You just want to keep working and not have to deal with Maven. But worry not, Eclipse and I are here to help! It's very easy to sort this out in only a few minutes!

# Step 1: Converting your project to a Maven project

This is a one-click deal in Eclipse. It's not even limited to Java projects! I'm using the Kepler Scala IDE and it's working perfectly. Note: this does NOT change your main project type. If it's a Java project, it STAYS a Java project. If it's a Scala project, it STAYS a Scala project. All this does is add another feature to the project. The "Convert to..." phrasing in Eclipse is a bit confusing.

You will get a dialog asking you for some configuration settings, but you can use the default ones for the time being. They can be edited at any time anyway. Click Finished. A little "M" icon should have now popped up next to your project icon. That's it! You can now start managing your dependencies with Maven! Pretty cool, huh? Moreover, your old referenced libraries (the traditional stuff on your build path) are still there! You can keep them there, or add them as Maven dependencies so that everything is nice and consistent. It's going to be very clear how to do that after you've read this little tutorial. It might be a bit of extra work, but it will make things much easier in the long run.

(Note that in obscure cases where you're using a custom run configuration to run Scala apps - e.g. when using Akka - special care needs to be taken and the Scala Library and Scala Compiler need to be manually added to the Bootstrap entries in the classpath, within the run configuration management window. You get weird errors otherwise. But again, this is just a corner-case I've stumbled upon while working with Maven and Scala.)