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.
Alright, in order to install the Git plugin for Eclipse (called EGit) you would need to do the following steps:
- In Eclipse, goto “Help > Install New Software…”
- 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
- Select the plugins/features checked in the following screenshot under the “Collaboration” node
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).
- Again, goto “Help > Install New Software…”
- Enter “http://download.eclipse.org/m2e-wtp/releases/” in the drop-down box and click “Add”
- Select the plugins/features checked in the screenshot below:
Next thing we do is to configure EGit. For that we have to perform the following steps:
- Goto “Preferences”
- Enter “Git” in the filter field in the top-left corner
- Select the “Configuration” node
- Copy & adjust the settings shown below as they match your environment (proxy, email, etc.)
Last remaining step is to configure Maven. It’s simple:
- Goto “Preferences”
- Enter “Maven” in the filter field in the top-left corner
- Select the “Installations” node
- 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:
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.
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.