44

I already have a small Java project. I want to move it to Maven, so I want to create the pom.xml using Eclipse so that I can build it using pom from a command prompt. I have not worked with Maven before, though I have worked with Ant.

How can I create the pom.xml for my Java project using Eclipse?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
M Sach
  • 33,416
  • 76
  • 221
  • 314

7 Answers7

33

You should use the new available m2e plugin for Maven integration in Eclipse. With help of that plugin, you should create a new project and move your sources into that project. These are the steps:

  • Check if m2e (or the former m2eclipse) are installed in your Eclipse distribution. If not, install it.
  • Open the "New Project Wizard": File > New > Project...
  • Open Maven and select Maven Project and click Next.
  • Select Create a simple project (to skip the archetype selection).
  • Add the necessary information: Group Id, Artifact Id, Packaging == jar, and a Name.
  • Finish the Wizard.
  • Your new Maven project is now generated, and you are able to move your sources and test packages to the relevant location in your workspace.
  • After that, you can build your project (inside Eclipse) by selecting your project, then calling from the context menu Run as > Maven install.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mliebelt
  • 15,345
  • 7
  • 55
  • 92
  • 4
    How would you add pom.xml to a project that was created before m2e was installed if somebody needed to add a project from github that's only available through maven. – EternallyCurious May 26 '13 at 09:30
26

This works for me on Mac:

Right click on the project, select ConfigureConvert to Maven Project.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xiaoxxcool
  • 311
  • 4
  • 8
23

If you have plugin for Maven in Eclipse, you can do following:

  • right click on your project -> Maven -> Enable Dependency Management

This will convert your project to Maven and creates a pom.xml. Fast and simple...

user219882
  • 15,274
  • 23
  • 93
  • 138
  • 3
    In order to get this plugin: Help -> "Install New Software" and add the link found on this page: http://wiki.eclipse.org/Maven_Integration Currently it is "http://download.eclipse.org/technology/m2e/releases" – Reza S Sep 17 '13 at 20:05
11

To create POM.XML file in Eclipse:

  1. Install M2E plugin (http://www.eclipse.org/m2e/)

  2. Right click on project -> Configure -> Convert to Maven Project

3

The easiest way would be to create a new (simple) Maven project using the "new project" wizard. You can then migrate your source into the Maven folder structure + the auto generated POM file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
light_303
  • 2,101
  • 2
  • 18
  • 35
2

To create pom.xml file follow the next steps:

  1. Right click on the current project
  2. Select Configure option
  3. Select Convert to Maven Project
  4. Complete all fields in Create new POM window
  5. Check "Delete original references from project"
  6. Click on Finish button

If eclipse show the the error "Maven error “Failure to transfer…", follow the next steps

  1. Copy the dependency to pom.

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-archiver</artifactId>
        <version>2.5</version>
    </dependency>
    
  2. Click right on your project

  3. Select Maven
  4. Select Update project
  5. Select Force Update of Snapshots/Releases
Jorge Santos Neill
  • 1,635
  • 13
  • 6
0

Right click on Project -> Add FrameWork Support -> Maven