Setting up Maven2 projects in Eclipse

Because I have been using Maven for some years now, I decided it was time to post a way to consistently setup a Maven project with nested modules in Eclipse. At most projects until now I just played around with Eclipse to get the setup correctly.
This is how I do it now:

  1. In Eclipse 3.2.2 I install the Maven2 plugin from this location.

  2. I open up a command prompt and create a new module with: (I assume you have already succesfully installed Maven)
    mvn archetype:create -DgroupId=net.pascalalma.myproject -DartifactId=myproject-core
    This gives the following output (if the plugin is downloaded and installed before):

  3. Then I create a Eclipse project for this module like this:
    mvn eclipse:m2eclipse
    This gives the following output (if plugin is downloaded and installed before):
  4. Next step is to import the project in Eclipse:

One final thing about Maven2 and Eclipse files:
When using a source version system (like SubVersion, for example) it is good practice to exclude the generated code and files from the versioning system. That’s why the following files shouldn’t be checked in SVN:

  • target dir
  • .project file
  • .classpath file
  • .settings dir

When using SVN and TortoiseSVN (my favourite SVN client) you can add the directory to the ‘ignore list’ by right clicking the folder and choose the option to add it to the ignore list, like this:

About Pascal Alma

Pascal is a senior software developer and architect. Pascal has been designing and building applications since 2001. He is particularly interested in Open Source toolstack (Mule, Spring Framework, JBoss) and technologies like Web Services, SOA and Cloud technologies. Lately he is having great fun by building iOS apps with Swift. Specialties: JEE AWS XML/XSD/XSLT Web Services/SOA Mule ESB/ WSO2 ESB Maven Cloud Technology Swift/ iOS
This entry was posted in Maven and tagged . Bookmark the permalink.