How to Mavenize an Existing Eclipse Project

General Guidelines on Mavenizing an Existing Eclipse project

  • Create an empty Maven project of the same type as your original project (i.e. jar, war…) using the appropriate archetype.
  • cd into the project directory that you just created and which now has a pom.xml file for your project.
  • Run mvn eclipse:eclipse -DdownloadSources=true in this directory.
  • Import the Maven project into Eclipse
  • Move the original project’s source code and resources into the new Maven project structure.
  • Get all your classpath dependencies into your pom.xml

See: How to Determine the Maven dependency to use for a jar

Note, that unlike Eclipse, Maven has the concept of test scope for those dependencies that are required for testing, but not by the application itself. For example, for JUnit you would typically add a dependency like:


If you do have an Ant build file, it may help you determine which artifacts are only required for tests.

  • Clean up your Mavenized project. For example, you don’t need your lib directory and Ant’s build xml anymore.
  • Make Maven happy. Suggested test:
  1. Delete you local maven repository
  2. Open a shell or command prompt and go where your project’s pom.xml is.
  3. Run mvn clean install
  4. Check if your local repo is back with your project and all the dependencies.
  • Make your Eclipse happy. If it isn’t:
  • Ensure that your M2_REPO variable is properly defined (this needs to be done once per workspace). If not, you can set this via the command:
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply