Skip to Content
Author's profile photo Matthias Steiner

Essentials – Working with Git & Maven in Eclipse

As stated in the first post of my “Essentials” series it’s all about lowering the entry barrier and helping newbies to get started with SAP Cloud Platform. So, in this blog post I quickly want to provide you with the ‘bare necessities’ to install the required tooling for Git and Maven for Eclipse in order to simplify the process of getting examples from social code sharing sites such as Github up and running.

Note: Please do not expect me to provide you with the ultimate beginners guide to the stated technologies! By no means do I want give impression that I’ll serve you all you need to know on a silver plate. You’d certainly be well-advised to familiarize yourself with these tools IF you want to stay in control of what you’re doing! All I want to achieve with this post is to help you with getting your setup right in just a few minutes – establishing a basecamp if you will – you still have to climb the rest of the mountain yourself though. 😉

Installing EGit

Alright, in order to install the Git plugin for Eclipse (called EGit) you would need to do the following steps:

  1. In Eclipse, goto “Help > Install New Software…”
  2. Depending on which version of Eclipse you use (we currently support Juno and Indigo) you have to select the corresponding Update Site from the drop-down box
  3. Select the plugins/features checked in the following screenshot under the “Collaboration” node

/wp-content/uploads/2012/11/egit_updatesite_152858.jpeg

Installing Maven for Eclipse

Now that we got EGit installed, we want to add Maven support: m2e-wtp. That may sound a bit cryptic (gotta love developers, right!), so let’s explain: it’s a Maven plugin for Eclipse that allows to use Maven-based projects in conjunction with the Web Tools Platform (WTP).

  1. Again, goto “Help > Install New Software…”
  2. Enter “http://download.eclipse.org/m2e-wtp/releases/” in the drop-down box and click “Add”
  3. Select the plugins/features checked in the screenshot below:

/wp-content/uploads/2012/11/m2e_updatesite_152864.jpeg

EGit configuration

Next thing we do is to configure EGit. For that we have to perform the following steps:

  1. Goto “Preferences”
  2. Enter “Git” in the filter field in the top-left corner
  3. Select the “Configuration” node
  4. Copy & adjust the settings shown below as they match your environment (proxy, email, etc.)

/wp-content/uploads/2012/11/egit_config_152904.jpg

Maven configuration

Last remaining step is to configure Maven. It’s simple:

  1. Goto “Preferences”
  2. Enter “Maven” in the filter field in the top-left corner
  3. Select the “Installations” node
  4. If you already haven Maven installed you want to point to a (global) pre-existing settings file. If not, you may want to create a settings.xml file and point to it here, e.g. if you want … aeh need to specifiy a proxy server etc.

So, that’s pretty much it… you may want to check that it all works fine by cloning one of the SAP Cloud Platform samples on Github. Let’s do it together…

Cloning a git repo(sitory)

So, let’s got to one of the easier samples on our Github account:

https://github.com/SAP/cloud-springrest 

/wp-content/uploads/2012/11/github_cloning_152884.jpeg

Copy the URL to the repo (https://github.com/SAP/cloud-springrest.git) by clicking the little notepad icon. (Note: As you can see from the screenshot I’ve been logged on with my Github user and as I’m a contributor to this project I have both Read + Write access.)

Now, let’s go back to Eclipse and open the Git perspective via the “Windows > Open Perspective > Other…” menu entry and the selecting the “Git Repository Exploring” option. In this perspective you have the “Git Repositories” view on the left. In the corresponding menu (top-right of the view), click on the “Clone Git repository and add the clone to this view” icon.

In the pop-up window, select “URI” as the repository source. Click next to get to the next step of the wizard. Here, all the details should already be pre-filled (if you have used the notepad button on Github!) If you should have a Github user and you do want to contribute to the respective repo, you may want to maintain your username/password in the authentication section at the bottom. But cloning the repo should equally well work without it. Press “Next” and skip over the next wizard step – there is no need to make any changes. On the third and last page, select the directory to clone this repo to. In general, it’s a good idea to store all your git repositories in a dedicated folder. Click on “Finish” to clone the repository.

/wp-content/uploads/2012/11/github_cloning2_152894.jpeg

Let’s switch to the “Java EE” perspective and use the “File > Import…” menu and then the “Existing Maven projects” option. Provide the link to the root directory and click on Finish. Now, the project sources should be imported into your workspace. We’re almost there…

Open up the project properties by using the context-menu of the project in the “Project Explorer” view. Select ‘Properties’ and then “Project Facets”. here, you need to convert the project to faceted form (This is an Eclipse-specific setting and hence – by design – not part of the Maven project nor the project repo.) Once this has happened you should see a “Dynamic Web Module” Facet being active. Select it. On the right hand side you should see a “Details/Runtimes” toggle. Switch to the “Runtimes” option and select “SAP Cloud Platform” as the designated runtime.

Last thing you need to do is to use the context.menu of the project to trigger the build by using the “Run As > Maven install” option. Once the build has ended successfully you can add the project to a local or remote server as you would do with non-Maven projects….

Hope this blog post is useful to some of you… let me know about your experiences (good AND bad!)

[UPDATE:] This blog post was updated on January 25th 2018 to fix some broken links and to adjust product names etc.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Robin Van Het Hof
      Robin Van Het Hof

      Cool, I didn't even know there was a Git plugin for Eclipse!...

      Author's profile photo Matthias Steiner
      Matthias Steiner
      Blog Post Author

      Here's a codetalk video we recorded the other day that walks you through this process:

      [embed width="425" height="350"]https://www.youtube.com/embed/XUb3ze19hmM[/embed]

      Author's profile photo Chris Paine
      Chris Paine

      Very useful video - helps with little things like explaining changing the maven project to be a multi-faceted web one so that it can be deployed to a HANA Cloud Platform instance.

      Thanks for posting. 🙂

      Author's profile photo Former Member
      Former Member

      Nice post, Matthias.

      By the way, installing add-ons in Eclipse is much easier and friendlier through the Help > Eclipse Marketplace wizard than the Help > Install New Software one.

      Very soon the additional steps for installing EGit and m2e-wtp won't be necessary because with the release in 2013 (Kepler) they will be included by default in the Eclipse IDE for Java EE Developers package.

      Author's profile photo Matthias Steiner
      Matthias Steiner
      Blog Post Author

      Hi Kaloyan,

      thanks for the info about the Marketplace and the Kepler release! Sounds promising...

      Cheers,

      Matthias

      Author's profile photo Robert Russell
      Robert Russell

      Hi Matthias,

      Thanks for the blog, I followed the link from the enterprise granny blog

      http://scn.sap.com/community/developer-center/cloud-platform/blog/2013/05/27/enterprise-granny-part-2-making-it-run-like-never-before

      One thing that I noted from this blog is the git link - to quote

      So, let's got to one of the easier samples on our Github account: https://github.com/sapnwcloud/springrest

      After cloning and nothing importing and no errors and no project to select, I went back to the gitub page and scrolled down and found.

      "We have moved to https://github.com/SAP/cloud-springrest"

      So after cloning that,I have published to the cloud.

      Back to the Granny blog for me now.

      Best Regards,

      Robert

      Author's profile photo Chris Paine
      Chris Paine

      Hi Matthias,

      would you have some advice for what Maven archetype to use when creating a new (rather than cloning from an existing repo) project?

      Finding it harder than I thought to migrate my project (which was not built using Maven) to maven and jpa.

      As a first attempt I've just updated my pom.xml to look like enterprise granny's and will remove/add dependencies as I go along.

      Do let me know if you can think of a better way to get a quick start. (guess I really should post this in the forums... )

      Thanks,

      Chris

      Author's profile photo Matthias Steiner
      Matthias Steiner
      Blog Post Author

      Hi Chris,

      hm, I usually skip the archetype selection altogether and just start off with a plain pom.xml and add my dependencies manually.

      Can't remember if I ever migrated a non-Maven project at all to be honest, hence I'm not sure what challenges you faced. There's an eclipse feature to turn a project into a "Maven project/facet" from what I know. I'd assume that the biggest difference between a Maven project and a non-Maven project would be the source folder structuring. Maybe the simplest way would be to create an empty Maven project and simply copy the sources and he web-app resources into the corresponding folders ?!?

      Cheers,

      Matthias

      Author's profile photo Chris Paine
      Chris Paine

      Thanks!

      I had the added complexity of already having my non maven project synced to github. In the end, created new maven project, imported the existing code from git repo, then created a new branch and went to town on moving/renaming all the folders. After a reasonable amount of work, code deploys and runs successfully. As I previously mentioned, I did have issues with eclipse not deploying the maven built war to saphcp server, but building its own war each time according to the details in the web deployment option in the project properties. Once I pointed this to the maven snapshot everything worked and deployment included the maven dependencies.

      Next step to get my jpa models to start storing some data.

      Cheers,

      Chris

      Author's profile photo Nigel James
      Nigel James

      5*'s just for the note in the second paragraph.

      Dev's dig in and learn new skills. You will love yourself for it.

      Thanks for a great blog Mattias.

      Author's profile photo Former Member
      Former Member

      because   wall       youtube.com   I can't see