views:

23

answers:

2

what do I need to do if I want to convert a eclipse project to start using maven2?

I know of the maven plugin, but do I need to modify the existing project?

Or should I just re-import into a newly created project?

+2  A: 

Steps I would take to convert a single Eclipse project include:

  1. Install m2eclipse
  2. Create a new maven project (skip archetype creation)
  3. Right-click the new maven project and run Maven > Update project configuration
    (This should give you the correct maven project layout folders src/main/java, ...)
  4. Set dependencies from old eclipse project in pom.xml
  5. Copy the source code + resources from the old into the new project
  6. (This might break whatever SVN/other links you had, so be sure to check the project in again)

That should be everything as I recall the steps without opening up Eclipse. Be sure to let me know if you run into any problems!

Trying to keep the existing Eclipse project and add maven as an after thought will just put you in a world of hurt if you don't have the correct project layout and/or dangling Eclipse managed dependencies.

Converting a set of projects working together might prove more difficult, but should include the same steps (with the addition of setting up a parent pom / modules / dependencies)

Tim
+1  A: 

Supposing you have m2eclipse installed, you can mavenize the existing Java project by just right click on project->Maven->Enable Dependency Management. Now project can be build with maven and you can manage dependencies in generated pom.xml. The disadvantage of this approach is that the existing project folder structure is preserved, so your project layout won't follow the maven standard convention.

If you don't have heavy reasons to stay with existing project, I would recommend to start new maven one and import your sources and resources into it, so you'll take advantage of meaningful maven defaults, that hopefully will save you a lot of time and nerves in using various plugins.

Gennady Shumakher