The new Maven/Eclipse integration - Part 1
Creating a new Maven project in Eclipse
A new and greatly improved version of the Maven 2 Eclipse plugin has just come out. In a series of short articles, I'll be looking at what's new, and how to get the most out of this new version.
In this first installment, we will look at how to create a new Maven project from within Eclipse.
Installing the plugin
You can install the Maven Eclipse Plugin in the usual way, by using the Sonatype update site: http://m2eclipse.sonatype.org/update.
Creating a new Maven project
In this new version, the Maven project Wizard has been considerably improved. You can open this wizard by selection "New -> Other" and then opening the "Maven" entry. At this point, you get to choose from four options:
- Check out a project from Subversion
- Create a new Maven project
- Create a new module
- Create a new POM.XML
There are still a few bugs to be ironed out here when using multi-module projects, though. In the current version, for example, the main project that you check out will be correctly configured for Subversion and Maven, but things like JUnit will not work out-of-the-box - you have to configure a new JUnit run configuration for each sub-project. It would be nice if you could use "Run As -> JUnit Test" from the contextual menu in the same way as for any other project.
In the other projects created in the Eclipse environment, on the other hand Maven is configured correctly and you can run your unit tests (and other things) from the contextual menu as you would expect. However, in these secondary projects, Subversion is not configured! A simple "Team -> Share Project" does the trick, but even so, it would be nice if it was automatic.
You can also create a brand new Maven project, using a wizard to define the general project metadata and dependencies. You can select the archetype you want to use from a very complete list of available archetypes, including archetypes from Appfuse, Codehaus, Tapestry, Apache and others. This is very cool - I can never remember the syntax for the mvn:archetype create command.
The third option is to create a module as a child of a parent project. The last option is to create a POM.XML file for an existing project, and lets you enter some basic project metadata and specify the dependencies.
Overall, the m2eclipse team have done a nice job. Although there are still a few minor issues to iron out, it is very promising - you'll never have to write a pom.xml file or run the mvn:archetype command by hand again!
Until next time...
John Smart
Optimizing your software development process
http://www.wakaleo.com | john.smart@wakaleo.com
John is a freelance consultant specialising in Enterprise Java, Web Development, and Open Source technologies, currently based in Wellington, New Zealand. Well known in the Java community for his many published articles, John helps organisations to optimize their Java development processes and infrastructures and provides training and mentoring in open source technologies, SDLC tools, and agile development processes. John is principal consultant at Wakaleo Consulting, and runs several Training Courses on open source Java development tools and best practices. John is a DZone MVB and is not an employee of DZone and has posted 58 posts at DZone. You can read more from them at their website.
- mr_john_smart's blog
- Login or register to post comments
- 6487 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Eugene Kuleshov replied on Wed, 2008/03/19 - 11:10pm
As for Subversion configuration, it doesn't really have anything todo with Maven integration. The issue is completely on Subclipse side, which explicitly disable sharing of the nested projects. The good news is that solution for this issue is in the works.
BTW, you have forgotten "Materialize Maven Project" option that allows to import projects into Eclipse workspace based on Maven metadata for the artifacts available from Maven repositories. I have blogged about that in more details at http://www.jroller.com/eu/entry/maven_project_materialization
Guillaume Bilodeau replied on Thu, 2008/03/20 - 8:44am
It's good to see improvement in this area. Maven/Eclipse integration has been poor at best until today, especially with regards to compile and runtime JAR dependencies - I always end up putting them in WEB-INF/lib anyway. Have you evaluated Q4E yet and if so, how does it stack up against the new m2eclipse?
Cheers,
GB
gumnaam suri replied on Fri, 2008/03/21 - 5:46am
Eugene Kuleshov replied on Fri, 2008/03/21 - 10:23am
in response to: gumnaam.sur
gumnaam suri replied on Fri, 2008/03/21 - 10:48am
Werner Keil replied on Mon, 2008/03/24 - 6:26pm
in response to: umnitsa
Interesting question.
Q4E is on the path towards a possible Eclipse Subproject.
Similar to Subversion, where at least 2 major Eclipse plugins compete, this seems a bit like that here, too.
Any plans to cooperate in the Eclipse Foundation on this?
hookfi replied on Sun, 2009/05/31 - 7:56am
akhileshkukreja replied on Wed, 2009/07/08 - 12:59am