How to Import a Maven Project into Eclipse

Project managed by Maven cannot be imported to Eclipse by default. However the conversion step is really simple.

1. Convert the project

Issue the command below at the project directory where pom.xml is found.

$ mvn eclipse:eclipse

This will generate the eclipse files, including .project and .classpath.

2. Add maven local repository to classpath at eclipse.

  • At Eclipse IDE, Select Window > Preferences
  • Select Java > Build Path > Classpath Variables
  • Click New button > defined a new variable named M2_REPO that pointing to your local Maven repository. For Linux, it will be ~/.m2/repository by default; for windows, it will be C:Documents and Settingsusername.m2repository by default.
  • Click OK all the way to finish the setting.

3. Eclipse>File>Import>Existing Projects into Workspace, just like you do for a typical Eclipse project.