Skip to Content

Deploy CAP Java App to SAP Business Technology Platform

Deploy the recently built bookstore application to SAP Business Technology Platform using the Cloud Foundry CLI.
You will learn
  • How to create a Cloud Foundry application manifest
  • How to deploy an application to SAP Business Technology Platform Cloud Foundry (SAP BTP) environment
renejeglinskyRené JeglinskyAugust 10, 2022
Created by
April 14, 2020

In the previous tutorial you made your application ready to run with SAP HANA. In this tutorial, you will deploy the application to SAP BTP, Cloud Foundry environment and have it running fully in the cloud.

  • Step 1

    When deploying an application to Cloud Foundry, you can use a manifest to describe attributes of the deployed application. The manifest can be used together with the Cloud Foundry CLI command cf push to deploy the application.

    1. Go to the ~/projects/bookstore folder and create a new file called manifest.yml.

    2. Add the following code to the newly created file and make sure you Save the file.

      - name: bookstore
        path: srv/target/bookstore-exec.jar
        random-route: true
        - bookstore-hana

    The manifest describes the name of the application and the path where the application archive can be found. Spring Boot applications can be deployed from a single JAR archive, which is what you are making use of here.

    The route of the application, meaning the HTTP endpoint where it will be available, will be randomized to prevent clashes with other application routes.

    The name of SAP HANA service instance you created in the previous tutorial is used here under the services section (bookstore-hana).

    When your application will be deployed to SAP BTP, it will use this database to store data instead of the in-memory database. In the previous tutorial you added the additional Java system property to your application to ensure that. When deploying the application to Cloud Foundry this is done automatically for you by the Cloud Foundry Java Buildpack.

  • Step 2

    Cloud Foundry uses the Open Service Broker API to provide services to applications. When running your application on Cloud Foundry, an environment variable VCAP_SERVICES (similar to the content of the default-env.json) is available, which contains all required service credentials. CAP Java can automatically read this environment variable and configure your application to use the SAP HANA database. In addition you want to make sure that your application is secure by default, when you deploy it to the cloud. The required dependencies for these aspects are included in the cds-starter-cloudfoundry dependency bundle. It also includes the cds-feature-hana dependency you added earlier.

    1. Edit the pom.xml in the srv directory (not the pom.xml file located in the root project folder) and under the <dependencies> tag replace the cds-feature-hana dependency you added in the previous tutorial with the cds-starter-cloudfoundry dependency. Make sure you Save the file.

    For what purposes the application manifest used for?

  • Step 3

    You are now ready to push your application to the cloud by running the following commands from the terminal in SAP Business Application Studio:

    1. Make sure that you are in the root of the bookstore project:

      cd ~/projects/bookstore
    2. Build your application once by running:

      mvn clean install

      The log output should be similar to this one:

      screenshot build log output
    3. Push the application to the cloud by running:

      cf push

      The manifest will be automatically picked up.

      Provide the credentials you usually log in to SAP BTP if you are asked to log in.

    4. To retrieve the application URL run the following command:

      cf app bookstore
      console output of cf apps
    5. Open the application in the browser. The according route can be found under routes of the previous step.

    6. Observe that your application is now secured by requiring authentication on service and entity endpoints. In the following tutorials you will learn how to configure authentication and authorization locally and in the cloud.

Back to top