Maven in Eclipse

Maven in Eclipse

In the past I have said some unkind words about about maven’s pom.xml format. My aversion to xml heavy configuration has drawn me to more lightweight approaches to build systems, like gradle for example. At the same time, I was intrigued: if a tool like maven is seeing such a widespread use despite its cumbersome format, there must something to make up for it. My curiosity finally got the better of me and I decided to give it a shot. I figured there might be some tooling available to help ease the pain.

And lo and behold, there’s not one but two eclipse projects for integrating maven. One is the IAM project (formerly known as Q4E) and the second is m2eclipse. In that regard it’s a bit like subversive/subclipse but hopefully without all that licensing nonsense. But it is usually  good to have some choice – and competition of course. To get a clearer picture I decided to give both plugins a try.


I started with IAM. Setting up my sample project was a snap, and the maven integration immediately started downloading dependencies and adding them to the project classpath. Maven repositories can also hold source jars, making development and debugging much easier. The pom editor seems to cover all options and is looking quite solid. I was more interested in the core feature set, so I didn’t check out any advanced options.


Next up I tested m2eclipse, which offers basically the same core feature set. Dependencies are automatically downloaded and added to the project classpath. The pom editor covered the same functionality as IAM’s, but I personally liked the the looks and layout better in m2eclipse. One really nice feature is code completion for dependencies.

I am too lazy to type...

Code completion – rocks!

I know I am spoiled eclipse developer, and I expect my IDE to finish my thoughts for me. But it gets even better: There is also a quickfix (Ctrl+1) for unresolved imports. Talk about convenience!

Quickfix to the rescue!

Quickfix to the rescue!

It’s good to see that there at least two very viable options when it comes to developing maven  projects in eclipse. Kudos to both the IAM and the m2eclipse team for the fantastic work.

The Price of Modularity

To me, one of the greatest strengths of the Java Platform has been its rich ecosystem. There are so many java libraries and frameworks out there, that when developing for the Java platform you almost never have to start from scratch. Most of the time it’s finding the right libraries, writing a little adapter code and the core business logic. No need for reinventing wheels. This truly is modular and reusable software development, and one of the main reasons why the Java platform is so competitive.

But this modularity does come at a price known as dependency hell. Any non-trivial project has a dozens of dependencies. Even your basic run-of-the-mill webapp requires a web framework, logging, OR mapper, JDBC drivers, etc. Add in all the indirect dependencies and you are looking at quite a lot of libraries. This is why strong dependency management is such a compelling argument for build systems like maven.

But there is another issue apart from painfully assembled builds: Jumpstarting new developers. Especially for open source projects it is quite a turnoff for a potential contributor to look at the long list of requirements and dependencies needed to get to the point where the code even compiles cleanly. This is where strong dependency management comes to the rescue. Sure, maven may download two and a half internets on the first compile, but when its done you have everything ready to start working.

“apt-get for Java”

Due to popularity and pervasiveness of maven, there are plugins for integrating almost all imaginable build tools. For most of projects maven provides everything needed right out of the box: unni testing, coverage, javadoc, pmd, you name it. Combined with hudson this makes it ridiculously easy to get a continuous integration server running literally within minutes.

It is good to see that automatic dependency management is making such inroads in different areas of computing. Apt-get and maven, and even p2 have helped a lot to make the dependency hell a little more bearable.

  • Tiran Kenja
    Posted at 10:10 am, September 17, 2009

    Why there are two official eclipse-maven integration projects is beyond me. But m2eclipse is likely to be the better one simply because it is being developed by Sonatype – who are also the main developers of Maven. Specifically they are doing a lot of work on Maven 3 to support better integration with IDEs and that in turn helps getting m2eclipse working better.

    The only real problem is that there seems to be no good solutions to do OSGi development with Maven, if you want to use the PDE tools.

  • Jason van Zyl
    Posted at 3:52 pm, September 17, 2009

    @Tiran, thanks for the vote of confidence. We have been doing a ton of work, and it’s simply not development but tons of testing, documentation, and professional QA. It’s not an easy task but I think we’re finally at the point where we have synchronized Maven 3.x trunk with M2Eclipse and we are now in a very fast cycle of pushing fixes through the whole toolchain when we see problems.

  • Stephen Lara
    Posted at 12:02 am, September 18, 2009

    I do not recommend using m2eclipse for very large projects. It will waste you time refreshing the pom.

  • Posted at 11:38 am, September 18, 2009

    I seem to remember when I tried the m2eclipse plugin a while back, one of the pre-reqs for using it was to run Eclipse using a JDK and not a JRE as it is defaulted to do.
    This meant either amending the desktop shortcut or the eclipse.ini file.
    I guess that is still the case.

  • Sakuraba
    Posted at 11:15 am, September 20, 2009

    I tried m2clipse and I was frustrated that I could not do “Right-Click-> Debug”, because m2clipse required me to set up a different eclipse project with some strange debug-settings and then use the Eclipse Remote Debugger and attach that to the VM that ran Eclipse.

    Waaay too complicated, although I must say that Maven and its conventions has brought a lot of good things to projects at our shop.