Eclipse with Java, Maven and Git setup


It took me awhile to perfect my setting up of Java-based projects in Eclipse that also utilize Maven and Git. I wasn’t sure in which order to do it, and if it should all be done inside Eclipse or not. So I thought I’d share my final process here. My version of Eclipse is Luna, although the general steps should work with other versions as well.

First you need Eclipse set up with the m2e (Maven to Eclipse) plugin. You will also need to install the EGit plugin. You need to have a regular “Workspace” set up, and optionally a Git local respository set up as well (NOT inside the Workspace – should be a separate directory). Or – you can let the EGit plugin create a Git repository for you.

In Eclipse, from the “File” menu, select “New” then “Other”. In the wizard that pops up, open “Maven” then select “Maven Project”. Click “Next”, then select the “Create a simple project” box.

In the next window, for Group Id – put your package name, and for Artifact Id – put your package name. Add a name for the project itself and other items if you like. Click finish.

The new project will be created in your regular workspace. For Git – remember you need to have the EGit Eclipse plugin installed.

To add your project to your Git repo, open up the “Java Browsing” perspective, and right click on the new project you just created. Look for the word “Team” in the menulist that pops up. Select “Team” (in my list it was 8th from the bottom), then “Share Project…”. Follow the prompts from there to use an existing repository or create a new one.

Now you should have a new Java Maven-based project in your Git repository. Notice the pom.xml file that is create. You will have to add your own dependencies to this.

Below is an example of the simple pom.xml file file that is created:

Leave a Reply