Setting Up the Development Environment – Eclipse , Java, Maven, SAP CAP ,Cloud Tools for SAP Cloud Application Programming Model
As explained in Capire documentation you can efficiently and rapidly build enterprise services and business applications in a full-stack development approach & and extend S/4HANA with your own choice of Tools ,your comfortable code Editors using SAP Cloud Application Programming Model, Fiori and Java or Node.js.
For a preconfigured development environment, use SAP Business Application Studio which comes with all of the required tools preinstalled. Just highlighting few tools hear i.e you no need to install most of tools if your going to use SAP Business Application Studio
However SAP Cloud Application Programming model (CAP) provides world-class support for developing based enterprise applications, whether you prefer SAP Business Application Studio (aka SAP WebIDE) , Eclipse, Visual Studio Code
Reference : https://cap.cloud.sap/docs/get-started/tools
- SAP Business Application Studio
For a preconfigured/automated development environment, use SAP Business Application Studio, which comes with all of the required tools pre installed,which offers a modern development environment tailored for efficient development ,test ,debug ,deployment of business applications for the SAP Intelligent Enterprise
Read hear Blog post : https://blogs.sap.com/2020/09/28/sap-business-application-studio/
It’s time to try out SAP Business Application Studio Onboarding/How to get it :Set Up SAP Business Application Studio for Development # Click hear for Tutorials/Exercises how to use SAP Business Application Studio
- Visual Studio Code (Set Up Local Development Using VS Code)
- Eclipse (Set Up Local Development Using Eclipse)
In this blog post we are going to learn “How to setup development environment if you are going to use Eclipse & JAVA to develop applications SAP Cloud Application Programming model (CAP) .
Reference : https://cap.cloud.sap/docs/java/getting-started
Installation Guide Index
This section describes the prerequisites required to build a CAP application locally, for example with Eclipse or Visual Studio Code or any Editor.
|Step No||Step Name||Details|
|1||Node JS (LTS Latest Version ) & other CLI Tools||https://nodejs.org/en/|
|Download Node JS (LTS Latest Version ) & other CLI Tools|
|Test (Optional) i.e Verify installation||node -v|
|2||NPM Registry Configuration||npm set @sap:registry=https://npm.sap.com|
|I,e Confirm installation|
|Test (Optional) I,e Confirm installation||npm config list|
|3||Install SAP CDS SDK||npm install -g @sap/cds-dk|
|Test (Optional)||CDS –version|
This section describes the prerequisites and tools required to build any kind of Java application Using Eclipse IDE (Step 4 to Step 7 )
|Step No||Step Name||Details|
|4||Install Java||Refer this document Step 4|
|5||Setup Maven||Refer this document Step 5|
|6||Install Eclipse for java||Refer this document Step 6|
|7||Install Spring Tools||Refer this document Step 7|
Next install SAP CAP Support Tools for Eclipse IDE to develop application using CAP Java .
It is intended to be used in the Help > Install New Software wizard of Eclipse.
Using Eclipse IDE
|Step No||Step Name||Details|
|8||Add the SAP Cloud Business Application Tools for Eclipse||https://tools.hana.ondemand.com/2020-06|
Advance Setup required for Cloud Foundry Environment of SAP Cloud Platform
Note : >> This Advance installation steps are not mandatory to start your local development & deployment .You can stick to above basic setup (Step1 to Step 8) >> If you are going to use SAP Business Application Studio then it is easy for your cloud application development ,test & deployment. You just need brower ,no need to install anything. i.e setup is automated as explain above in Introduction section >> If you have CI/CD pipeline then also you no need to setup "Advance section" for deployments to your dev space in cloud.
CAP applications can be deployed into the Cloud Foundry Environment of SAP Cloud Platform. At the end, it’s about deploying regular Node.js and/or Java applications, and about creating and binding appropriate service instances (see the CF Developer Guide).
you can run below commands from command prompt
|Step No||Step Name||Details|
|9||Chocolatey||@”%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin” choco install -y nodejs-lts sqlite make curl jq cloudfoundry-cli|
|10||Install Windows Build Tools||npm install –global windows-build-tools|
|11||Cloud Foundry CLI||cf install-plugin multiapps|
|12||MTA plugin for the CF CLI.||1.Install the MTA Build Tool|
|npm install -g mbt|
|i.e Confirm installation||cf|
Let’s see above steps in detail
Step 1: Download & Install Node JS (LTS Version ) & other CLI Tools
For windows Machine download msi & then just double click
& Follow wizard for Installation
Here are Screenshots for your reference on how to install node js
Optional ,you can also install Chocolatey & other tools using npm/powershell scripts
Step 2 : NPM Registry Configuration for Command-Line and Build Tools
You can use the npm command to configure the SAP target registry for the current session:
- Either using command prompt
- Or manually edit .npmrc file
#1) Just run below command from command prompt
npm config set @sap:registry https://npm.sap.com
#2) Alternatively you can also add below code in NPM Registry Configuration in the .npmrc File
Location of file : C:\Users\xxxxxxxx
Confirm installation (Optional step)
This step is just to verify whether configuration is correct or not.Just run from command prompt
npm config list
Note : Resolving EACCES permissions errors when installing packages globally
Step 3: Setup CDS SDK
Open a command line window and install the cds development kit globally by executing the following command
npm i -g @sap/cds-dk
npm install –global @sap/cds-dk
- This process takes some minutes installing the cds command, which you will use in the next steps.
- To verify that the installation was successful, run cds without arguments
- You can verify version using below command cds –version
- If you have On MacOS/Linux machine , you may need to follow the steps as described here.
- If there’s an older @sap/cdspackage already installed on the machine, you may have to remove it first; if so, you’ll be instructed to do so. In case of problems, see the Troubleshooting guide for CAP.https://cap.cloud.sap/docs/advanced/troubleshooting#npm-installation
Step 4 to Step 8 are specific to Ellipse and Java
Step 4: Install Java
You can install SAP supported version of OpenJDK for SAP customers and partners who wish to use OpenJDK to run their applications i.e SAP Machine which install JAVA which is close to JAVA OpenJDK/OracleJDK
Note: As an alternative option you can also use JAVA OpenJDK/Oracle JDK
Install a Java VM. At least, Java 8 is required.
Installation Steps : https://github.com/SAP/SapMachine/wiki/Installation
Steps to install SAP Machine (SAP JAVA)
- Using the Windows Installer (download the MSI package) is the simplest way to install SapMachine on Windows.
2) Just Double click or Run msi
3) Follow Wizard for installation (you can refer below screenshots)
- Once you install Java, you need to set Environment variables
There are two choices as there are two types of environment variables: user environment variables (set only for current user) and system environment variables (set for all users).
The variable (ex: “%UserProfile%”) is used as a type of shortcut of the value (ex: “C:\Users\<username>”).
Just type System Environment Variables in Windows Search
In Windows in order to set
Step 1 : Right Click on MyComputer and click on properties .
Step 2 : Click on Advanced tab
Step 3: Click on Environment Variables
Or You can also go to Environment Variables from Windows Search,then Type “Edit the system environment variables ”
Just run below command
Step 5: Install Maven
- Go to (Maven Website à Use –> Download –> Download the Binary zip archive.)
Or click hear https://maven.apache.org/download.cgi
- Download latest zip file
- After the download, unzip the folder and copy it to the folder. (Let’s say i have copied /extracted to location
- Add Path to System User Environment variables & System environment Variables
Setting the path of Maven in environment Variables: Search the Environment Variable –> Edit the System Environment variables–> Navigate to Advanced tab — > Environment Variables
i) MAVEN_HOME :
Click New –> Variable Name : MAVEN_HOME
Variable Value: C:\Program Files\apache-maven-3.6.3
ii) M2_HOME :Click New –> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
iii) Edit the ‘Path’ Environment Variable –>
Update the PATH variable by appending the Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere.
Testing whether Maven is installed:
Open command prompt & type
in the command prompt. It should display the Maven version, the java version, and the operating system information. That’s it, you have set up Maven on your Windows system
- Verify Whether u already have .m2 folder in user directory
Just type %userprofile% in windows run to go to your user directory
This folder required for your to have all maven repositories
You have run “mvn package” command from command prompt
- Configure Maven for the SAP build landscape by downloadingxml and save it to <USER_HOME>/.m2/settings.xml
Step 6: Install Eclipse
Install the Eclipse IDE for Enterprise Java developers.
Screenshots : Follow wizard as shown below
JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. The JDK includes the JRE, so you do not have to download both separately
JRE provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language. No need to have JRE when you have JDK.
Next, select “Windows > Preferences” (PC) or “Eclipse > Preferences” (Mac) in the menu. Then, select “Java > Installed JREs”:
If you would have installed SAP Machine then in Eclipse –> Installed JREs –> JRE Path you can add as “C:\Program Files\SapMachine\JDK\11”
Step 7: Add Spring Tools 4
Install the Spring Tools 4 Eclipse plugin that makes development of Spring applications more convenient: From the Eclipse Marketplace (Help > Eclipse Marketplace…) search and install Spring Tools 4.
Step 8: Install Eclipse Tools for SAP Cloud Application Programming Model
The Eclipse Tools for SAP Cloud Application Programming Model offer support for the Core Data Services (CDS) language and provide features to build, deploy and test business applications and services
Install the Eclipse plugin called SAP Cloud Business Application Tools for Eclipse that supports convenient editing of CDS files.
- In Eclipse open Help > Install New Software….
- Add the following update site location: http://download.xsjtools.c.eu-de-1.cloud.sap/sites/eclipse/release/
- Select SAP Cloud Business Application Tools> SAP Cloud Business Application Tools for Eclipse.
- Click Next and Finish, accept the license agreement and warning about unsigned content, restart Eclipse.
For SAP Cloud Application Programming Model in general see the documentation
Step 8.1 –> Install Additional SAP Development Tools for Eclipse Installation
Below is optional step not mandatory
You can also follow below steps & Install the additional SAP Development Tools for Eclipes
From the Eclipse menu, choose Help > Install New Software…
Add the URL of the tools update site for your Eclipse release, e.g: https://tools.hana.ondemand.com/2020-06
Then follow the steps of the installation wizard.
You can also install SAP HANA Tools ,SAP Modelling tools for Eclipse
For more information about the features see the embedded help
Reference : development environment.
Below is optional step not related to SAP Cloud Application Programming Model
- SAP Cloud Platform Tools
- Other tools: installation instructions are linked on https://tools.hana.ondemand.com/ (see tool specific tab)
- Direct link to the Tools Update Site: https://tools.hana.ondemand.com/
Typical error messages are:
>>No repository found at https://tools.hana.ondemand.com/ Eclipse Release Name
>>Could not find tools.hana.ondemand.com
>>Unable to connect to repository at https://tools.hana.ondemand.com/ EclipseReleaseName
Probably, you did not configure the proxy correctly in Window > Preferences > General > Network Connections so that Eclipse can not reach https://tools.hana.ondemand.com. The correct proxy configuration depends on your IT infrastructure. The following 3 typical configurations have been reported as working in the support forum:
You can connect directly to the internet, i.e. don’t need any proxy.
Please configure ‘Direct’ as Active Provider.
You connect to the internet via http proxy.
Please configure ‘Manual’ as Active Provider and configure the proxy entries for the protocols HTTP and HTTPS. Do not configure anything for SOCKS.
You connect to the internet via SOCKS proxy.
Please configure ‘Manual’ as Active Provider and configure the proxy entry for the protocol SOCKS.
To find the right setup, you could check the proxy settings in your browser.
After fixing the proxy configuration, please go to Windows > Preferences > Install/Update > Available Software Sites, select e.g. the software site “SAP Development Tools for Eclipse Oxygen” and press ‘Reload’ to verify that the connection works now. Repeat the check for software site ‘Oxygen’ (http://download.eclipse.org/releases/oxygen).
> On Windows, users experienced problems with the ‘Native’ proxy provider. Therefore, we recommend to use the ‘manual’ proxy provider and to configure the proxy settings manually.
> On the update site, there is no file https://tools.hana.ondemand.com/EclipseReleaseName/content.xml (even though Eclipse complains about it in the error message). If you want to test that you can download a file via browser, please test with https://tools.hana.ondemand.com/ <EclipseReleaseName>/content.jar (e.g. https://tools.hana.ondemand.com/oxygen/content.jar)
Please also test if you can install from the eclipse.org update site (https://download.eclipse.org/releases/<EclipseReleaseName>
e.g. http://download.eclipse.org/releases/oxygen). If not, please check the proxy settings again.
In case your connection to the update site is very slow, you may run into timeouts (check the error message details). The following article helps to workaround the timeouts:
If this does not solve your problems then please request support in the SAP Cloud Platform Community .
Finally Verify the Setup
Execute the following commands on the command line to check whether the installed tools are setup correctly:
Starting a New CAP JAVA based Project
Take the following steps to set up a new CAP Java application based on Spring Boot from scratch.
How to start new Java project
Two choices you can generate new CAP JAVA project either using
- CAP Java Maven Archetype
- Using “CDS init “command
#1) Using the CAP Java Maven Archetype
Use the CAP Java Maven archetype, that is run behind the scenes of cds init, which allows to specify additional options: Screenshots for your reference
mvn archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds -DarchetypeVersion=RELEASE
When prompted, specify the group ID and artifact ID of your application. The artifact ID also specifies the name of your projects root folder that is generated in your current working directory. For other values prompted, it’s enough to simply confirm the default values.
Then you can import project in Eclipse focus on modeling entities & writing services using CDS
- Open Eclipse , then Select File menu > Import… > SAP Cloud Business Application.
- Select the xmlfile in your project and click Finish.
Example : If you need some example model or test cases , just add some additional parameters in above command
mvn archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds -DarchetypeVersion=RELEASE -DincludeModel=true -DincludeIntegrationTest=true
- -DincludeModel=true: Adds a example sample CDS model to the project
- -DincludeIntegrationTest=true: Adds an integration test module to the project
The generated project has the following folder structure:
<PROJECT-ROOT>/|– db/`– srv/ |– src/main/java/ |– src/gen/java/ |– node/ `– node_modules/
The generated folders have the following content:
- db: Contains content related to your database i.e CDS models
- srv: Contains the CDS service definitions and Java back-end code
- srv/src/main/java: Contains Java application logic.
- srv/src/gen/java: Contains the compiled CDS model and generated accessor interfaces for typed access.
- nodeand node_modules: Contain a local Node.js installation and dependencies for the CDS compiler unless you specify -Dcdsdk-global when starting the build.
To not be distracted by CDS tools-specific folders in Eclipse, you can define resource filters. Open the context menu on the project’s root folder and select “Properties”. Go to Resource > Resource Filters” and exclude folders with the name node and node_modules.
#2) As an alternative ,you can also use the CAP CDS init command
Alternatively, you can use cds init to bootstrap a CAP Java application based on Spring Boot. Run the following command:
cds init <PROJECT-ROOT> –add java
You can also specify the package name through parameter –java:package. Default for the package name is: org.<PROJECT-ROOT>.
cds init <PROJECT-ROOT> –add java –java:package <java package name>
The artifactId is set to <PROJECT-ROOT> and the groupId to customer
Import the CAP JAVA Project
- In Eclipse , Select File > Import… > SAP Cloud Business Application.
- Select the xmlfile in your project and click Finish.
Compile the CAP JAVA Project
- In Eclipse ,Right-click on the xml file in the project root folder and select Run as > Maven build
- Enter the string clean install to the field labeled with Goals and click Run.
Note : This step compiles your CDS artifacts. Repeat this step once your CDS model changes.
You can also run mvn clean install from command prompt form your project location.
Run and Test the Application
- Right-click on the project root in the Package Explorer and select Run as > Spring Boot App.
or from command prompt run below command by navigating to your project root folder
- Call the application in your browser at http://localhost:8080/.
This should show the automatically generated index page of served paths for oData Services /Rest API’s
Note : To Install the dependencies of the
dbCAP module manually and suppress the npm scripts: cd db npm install --ignore-scripts
How to obtain support /help
- In case of problems, see the Troubleshooting guide for CAP.https://cap.cloud.sap/docs/advanced/troubleshooting#npm-installation
- If this does not solve your problems then please request support in the SAP Cloud Platform Community .