Incorporate Maven into Eclipse project

28 04 2012

Here is short instruction how to incorporate Maven into existing Eclipse projects from scratch, step by step. The goal of Maven introduction presented here is quite generic, however I installed Maven to manage dependencies (jars). Maven build, installs or clean functions are not used by me. If You need to know more about maven itself – this screencast is good start.

1. Install eclipse plugin for maven
I recommend m2eclipse as it is most popular and works quite well. It is supported by Eclipse: 3.6 Galileo and 3.7 Indigo. Install it by ‘Install new software‘ Eclipse option. Update site link you will find on this site.

This will install its own Maven instance, so you don’t need to install Maven yourself – m2eclipse will handle it. However manual Maven installation is necessary if You need another version that is provided in m2eclipse by default.

Some very good introduction about m2eclipse is here. If m2eclipse doesn’t suit you, then you can find another plugins comparison here. The best one decided on is however m2eclipse.

2. Update existing project with maven functionality
(If You are creating new project use Eclipse -> New Project and choose type: Maven. Params to enter are the same as described below)

To create pom.xml file and tell to m2eclipse to use this file:

Right click on project -> configure -> Convert to maven project

On the project configuration dialog You need to fill in these fields:

  • groupId – in fact this is main package name that is used in eclipse project. Param states that project belongs to some group, pointed by package name.
  • artifactId – project name that is used in Eclipse. This will be the name of the file that will be produced by Maven after compilation (e.g. name of external jar)
  • archetype – project type. This is similar to creating new project in Eclipse, where You choose on of the project types at the beginning (Android project / Java project / Dynamic Web Project etc.). Like Eclipse project types, Maven provides its archetypes. Choosing proper one, eases project configuration. Maven preconfigures its structure and pom.xml file.
  • dependencies – list of all jars or another workspace projects required for Mavenized project to run. Referenced workspace projects should also be maven ones.

3. Updating Maven project configuration
After making changes in Maven config (pom.xml file) you will have to update project configuration to reflect these changes in project.
Do it by:

Right Click on th project -> Maven -> Update project configuration

4. That’s all

On another computer, where this project is used it is enough to install m2eclipse (point 1.) and trigger ‘Update Project Configuration’ (point 3.).

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!



3 responses

5 05 2012
Basic Maven (m2eclipse / pom.xml) configuration « Looks OK!

[…] 5 05 2012 Introducing Maven to Eclipse projects from scratch was described in my previous post. Now the basic usage and configuration will be […]

12 05 2012
Use Maven with Android project « Looks OK!

[…] All instructions how to do it, You will find here. […]

17 11 2012
Maven & Android: complete pom.xml files contents « Looks OK!

[…] files are operational, after performing all maven, m2eclipse and maven for android plugin […]

Give Your feedback:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: