Getting Started on Linux
Get SAP Cloud SDK Development Environment for Java on Linux
This tutorial will guide you through getting your SAP Cloud SDK development environment up and running on Linux. All the steps were verified on Ubuntu 18.04 and should comply with other Debian-based distributions.
Required Knowledge
No initial knowledge is required.
Let's Install Dependencies
Installing the Java Development Kit and Maven
SAP Cloud SDK supports Java 8 and Java 11.
I'll base this example on Java 8.
sudo apt-get install openjdk-8-jdk
Updating alternatives to make sure the right version of Java is used.
Your distribution might have a different version of Java installed by default. You can check your Java version by running:
java -version
As you can see below, my laptop has Java 11 as default.
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.1)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.1, mixed mode)
Check what Java versions you have on your machine with:
update-java-alternatives --list
After installing OpenJDK 8 you should now have both Java 8 and Java 11.
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
To switch between Java versions run:
sudo update-alternatives --config java
In my case, I have to press 2 to make Java 8 default.
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
*1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Check the Java version again.
Mind, the version
parameter has just one hyphen for Java 8 CLI.
java -version
You have now switched to Java 8.
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-8u232-b09-0ubuntu1.1-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
Use Maven To Build and Deploy Your App
Install maven
with:
sudo apt-get install maven
To check if maven
is installed correctly run:
mvn --version
You'll see the maven version and build details.
Apache Maven 3.6.1
Maven home: /usr/share/maven
Java version: 1.8.0_232, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "5.3.0-26-generic", arch: "amd64", family: "unix"
To find out more about Apache Maven, how to get it for your Linux distribution, and detailed tutorials follow the official maven documentation.
Cloud Foundry Command Line Interface
To deploy your app developed with SAP Cloud SDK to SAP Business Technology Platform you'll need the Cloud Foundry command-line interface (CLI).
You can download the latest release of the DEB package from the official CF GitHub repository or follow instructions to install it with you package manager: apt-get
, yum
and homebrew
are supported.
After installing the CLI, you might need to reload your shell before it becomes available. To check if it works run:
cf
Installing IntelliJ Idea IDE
For the best developer experience, we recommend getting the community version of IntelliJ Idea. Download the archive from the official site and follow installation instructions for your system.
Another supported IDE is Eclipse.
Initialize and Build Your App
To Initialize Your SAP Cloud SDK App From the Maven Archetype
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.sdk.archetypes -DarchetypeArtifactId=scp-cf-tomee -DarchetypeVersion=RELEASE
The snippet above will create a TomEE
app, you can also use archetype for Spring Boot.
Building Your App
Change the directory to the root of the app you've just created.
cd /<app-root-directory>
To build your APP run:
mvn clean package
After a successful build, you'll find a target
folder within your app's root folder containing a war
file along with other build artifacts.
This war
file is a packaged version of your web-app that's going to be deployed in the SAP Cloud Foundry environment.
Bind your Command-Line Interface to an API Endpoint
Let's associate your Cloud Foundry(CF) CLI to your SAP account by providing an API endpoint and logging in with your account.
Select endpoint depending on your region:
- Europe https://api.cf.eu10.hana.ondemand.com
- US East: https://api.cf.us10.hana.ondemand.com
- US CENTRAL: https://api.cf.us20.hana.ondemand.com
To use a snippet for Europe run:
cf api https://api.cf.eu10.hana.ondemand.com
Provide your credentials for the SAP BTP by running:
cf login
Deploying Your App
To deploy your app run:
cf push
After a successful deployment, you'll see a status of just pushed app:
Waiting for app to start...
name: test-app
requested state: started
isolation segment: trial
routes: test-app-shy-hyena-st.cfapps.eu10.hana.ondemand.com
last uploaded: Sun 12 Jan 14:29:02 CET 2020
stack: cflinuxfs3
buildpacks: sap_java_buildpack
type: web
instances: 1/1
memory usage: 1024M
start command: JRE_HOME="META-INF/.sap_java_buildpack/sapjvm" JBP_CONFIG_SAPJVM_MEMORY_STACK_THREADS="250" JBP_CLASSPATH="" JBP_CONFIG_SAPJVM_MEMORY_CLASS_COUNT="" JAVA_HOME="META-INF/.sap_java_buildpack/sapjvm"
JBP_CONFIG_SAPJVM_MEMORY_HEADROOM="0" CATALINA_HOME="META-INF/.sap_java_buildpack/tomee7" JAVA_OPTS=" -Djava.io.tmpdir=$TMPDIR -Dhttp.port=$PORT -Daccess.logging.enabled=false
-Dlogback.configurationFile=file:META-INF/.sap_java_buildpack/tomee7/conf/logback.xml -DSAPJVM_EXTENSION_COMMAND_HANDLER=com.sap.xs2rt.dropletaddon.JvmExtensionCommandHandler
-Djava.protocol.handler.pkgs=com.sap.xs.statistics.stream.handling.protocols -agentpath:/app/META-INF/.sap_java_buildpack/jvm_kill/jvmkill-1.12.0.RELEASE-trusty.so=printHeapHistogram=1 -Dsun.net.inetaddr.ttl=0
-Dsun.net.inetaddr.negative.ttl=0" ./META-INF/.sap_java_buildpack/tomee7/bin/catalina.sh run
state since cpu memory disk details
#0 running 2020-01-12T13:30:29Z 69.0% 446.2M of 1G 191.1M of 1G
To verify your deployment take a URL
indicated in the routes
section from the deployment output above.
Put it into your browser and add /hello
at the end.
It should look similar to: https://test-app-shy-hyena-st.cfapps.eu10.hana.ondemand.com/hello
.