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 IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Maven and tagged . Bookmark the permalink.