Deploying CAP: HANA, XSUAA and MTA

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

While you develop a CAP application it runs on your own computer: the data lives in a throwaway SQLite database, the users are made up, and nothing sits in front of the server. A production application needs a real database, real logins and a way for SAP BTP to find, start and connect all of its parts. This page shows how a CAP project is prepared for that, built into a single archive and deployed to the Cloud Foundry environment of SAP BTP. You will read the files that the CAP command line writes (cds add hana, cds add xsuaa, cds add mta and cds add approuter), a real mta.yaml with every part explained, the output of cds build --production and of mbt build, and the commands that deploy the archive. The page applies to CAP Node.js 10.2 (@sap/cds 10.2.2, @sap/cds-dk 10.2.1, Node.js 22.12 or newer) and CAP Java 5.2 (Java 21 or newer, 25 recommended), as documented on 2026-11-13. The files and commands are shown for CAP Node.js, because the lab of this site is a Node.js project; the CAP guide for Cloud Foundry covers both runtimes, and a few Java differences are named where the guides give them. SAP BTP remains the documented name of the platform, and SAP now presents its capabilities as part of SAP Business AI Platform. Everything up to and including mbt build ran for real on a copy of the lab project; the steps that talk to Cloud Foundry, to SAP HANA Cloud or to a subaccount need an SAP BTP account, so they are described and labeled instead of run.

Before you read

Key terms

  • Multitarget application (MTA): one application made of several parts, such as a server, a database deployer and an application router, that are built, deployed and versioned together.

  • MTA archive (MTAR): the single file that holds the deployment descriptor and the built content of every module.

  • HDI container: an isolated schema in SAP HANA Cloud that SAP HANA Deployment Infrastructure fills from design-time files.

  • Application router: the single point of entry that authenticates users and forwards requests to the server module.

  • XSUAA: the SAP Authorization and Trust Management service that issues the tokens the application checks.

  • Cloud Foundry environment: the environment of a subaccount in which the modules of the archive run as applications.

  • Multitenancy: serving several customers (tenants) from one running application while keeping their data apart.

What changes between your laptop and SAP BTP

CAP’s guide for Cloud Foundry says that a project developed the CAP way starts with an in-memory database and basic, mocked authentication, and that in the cloud you typically use production-grade services such as SAP HANA and an authentication provider. Its command cds add <facets> configures those services and adds their dependencies to package.json. The lab project expenses of this site (Example Trading Co., EX01, claims as the teaching model) shows the difference directly, because cds env prints the setting that is in effect under each profile. All outputs below are real and shortened to the lines that matter, and they were produced after the four facets were added (the next section adds them).

npx cds env get requires.auth
npx cds env get requires.auth --profile production
npx cds env get requires.db --profile production
{
  "restrict_all_services": false,
  "kind": "mocked",
  "users": {
    "alice": {
      "tenant": "t1",
      "roles": [
        "admin"
      ]
    },
[...]

{
  "vcap": {
    "label": "xsuaa"
  },
  "kind": "xsuaa"
}

{
  "impl": "@cap-js/hana",
  "data": [
    "db/data",
    "db/csv"
  ],
  "pool": {
[...]
  },
  "kind": "hana"
}

Source: real output of cds env (CAP command line tools 10.2.1), each output shortened at the [...] marks (the first by the other mocked users, the third by the connection pool settings); without the profile, requires.db shows the implementation @cap-js/sqlite with the database URL :memory:; command described on CAP: Deploy to Cloud Foundry

Concern Development (cds watch) Production on Cloud Foundry

Database

SQLite in memory, @cap-js/sqlite

SAP HANA Cloud through @cap-js/hana, in an HDI container

Users

Mocked users such as alice

XSUAA tokens, checked by @sap/xssec

Entry point

The server itself on port 4004

The application router in front of the server module

Process

cds watch restarts on every change

Cloud Foundry applications created from an archive

CAP’s SAP HANA guide states that SAP HANA Cloud is the CAP standard database and is recommended for productive use, with full support for schema evolution and multitenancy, and that CAP is validated against SAP HANA Cloud rather than other SAP HANA variants. The CAP guide for Cloud Foundry also notes that the default index page and the SAP Fiori preview of local development are meant only for the development profile and are not available in the cloud, so a deployed application needs a real user interface.

Prepare the project once: cds add

The preparation is done once in the lifetime of a project. The lab project was copied to a scratch directory, installed with npm ci, put under git so that the changes can be shown, and then given all four facets in one command. Nothing else was edited by hand.

npx cds add hana,xsuaa,mta,approuter
git status --short
Adding facet: mta
Adding facet: xsuaa
Adding facet: hana
Adding facet: approuter

Successfully added features to your project

 M package.json
?? .deploy/
?? mta.yaml
?? xs-security.json

Source: real output of cds add (CAP command line tools 10.2.1) in a copy of the lab project; the facets are listed on CAP: Deploy to Cloud Foundry

Each facet has a visible footprint. The changes to package.json are small enough to show in full.

   "dependencies": {
-    "@sap/cds": "10.2.2"
+    "@cap-js/hana": "^3",
+    "@sap/cds": "10.2.2",
+    "@sap/xssec": "^4"
   },
@@
+  "cds": {
+    "requires": {
+      "[production]": {
+        "auth": "xsuaa"
+      }
+    }
   }

Source: real git diff package.json after cds add hana,xsuaa,mta,approuter, shortened to the changed hunks

  • cds add hana adds the driver package @cap-js/hana, which CAP’s SAP HANA guide names as the dependency for Node.js (for Java it names the Maven artifact cds-feature-hana). The guide adds that cds add does the equivalent of npm add @cap-js/hana and also updates mta.yaml and other deployment resources. The descriptor below contains the expenses-db resource and the expenses-db-deployer module that belong to the database.

  • cds add xsuaa adds @sap/xssec, switches auth to xsuaa in the production profile only (the cds env output above shows development still mocked), writes xs-security.json, and the descriptor below contains the expenses-auth resource for it. The CAP guide says the roles and scopes of xs-security.json are derived from the authorization annotations of the CDS model and must be regenerated with cds compile --to xsuaa when those annotations change. The lab model has no authorization annotations, so the generated file is real but empty: {"scopes": [], "attributes": [], "role-templates": []}. The page on XSUAA shows the same file for a model that has roles.

  • cds add mta writes mta.yaml, the deployment descriptor read in the next section.

  • cds add approuter writes a folder .deploy/app-router with three files: package.json (the @sap/approuter dependency, version ^23.0.0, and a start script), xs-app.json and default-env.json. The CAP guide lists cds add approuter as a custom application router setup without the SAP Cloud Portal service, and lists cds add portal and cds add workzone as other ways to serve user interfaces. The routing file it generated is a single catch-all route:

{
  "routes": [
    {
      "source": "^/(.*)$",
      "target": "$1",
      "destination": "srv-api",
      "csrfProtection": true
    }
  ]
}

Source: real .deploy/app-router/xs-app.json written by cds add approuter; the file format is described on SAP Help: Application Router

The application router’s own documentation describes the application router as the single point of entry of an application on the Cloud Foundry environment: it serves static content, authenticates users, rewrites URLs and forwards requests to other microservices while propagating user information. The routes of xs-app.json decide which request goes to which destination. Here every path goes to the destination srv-api, which the descriptor connects to the server module.

For CAP Java the same cds add commands exist. The CAP SAP HANA guide says that for Java the hybrid setup needs further configuration described in its own tutorial, so check the Java guides before you rely on the Node.js result shown here.

The deployment descriptor: mta.yaml

A multitarget application (MTA) is, in SAP’s words, essentially a single application that consists of multiple parts, created with different technologies, that share the same lifecycle. The MTA model consists of modules, resources and the dependencies between them. A module is a self-contained piece that is developed, packaged and deployed, such as a Node.js server. A resource is something a module needs at runtime that the module does not provide itself, such as a database or an authorization service. SAP’s page explains that the file mta.yaml is the development descriptor: it lists the modules, resources and properties and what depends on what. A second file, mtad.yaml, is the deployment descriptor that the SAP Cloud Deployment service reads, and a build tool produces it from the first. When you build with the Cloud MTA Build Tool, SAP’s page says that you must create mta.yaml yourself, which is what cds add mta does for you. This is the complete file cds add mta wrote for the lab (the cds add step ran first, so it also reflects the other three facets).

_schema-version: 3.3.0
ID: expenses
version: 1.0.0
description: "Teaching CAP project for the SAP guides. Not SAP software."
parameters:
  enable-parallel-deployments: true
build-parameters:
  before-all:
    - builder: custom
      commands:
        - npm ci
        - npx cds build --production
modules:
  - name: expenses-srv
    type: nodejs
    path: gen/srv
    parameters:
      instances: 1
      buildpack: nodejs_buildpack
    build-parameters:
      builder: npm-ci
    provides:
      - name: srv-api # required by consumers of CAP services (e.g. approuter)
        properties:
          srv-url: ${default-url}
    requires:
      - name: expenses-auth
      - name: expenses-db

  - name: expenses-db-deployer
    type: hdb
    path: gen/db
    parameters:
      buildpack: nodejs_buildpack
    requires:
      - name: expenses-db
  - name: expenses
    type: approuter.nodejs
    path: .deploy/app-router
    parameters:
      keep-existing-routes: true
      disk-quota: 256M
      memory: 256M
    requires:
      - name: srv-api
        group: destinations
        properties:
          name: srv-api # must be used in xs-app.json as well
          url: ~{srv-url}
          forwardAuthToken: true
      - name: expenses-auth
    provides:
      - name: app-api
        properties:
          app-protocol: ${protocol}
          app-uri: ${default-uri}

resources:
  - name: expenses-auth
    type: org.cloudfoundry.managed-service
    parameters:
      service: xsuaa
      service-plan: application
      path: ./xs-security.json
      config:
        xsappname: expenses-${org}-${space}
        tenant-mode: dedicated
        oauth2-configuration:
          credential-types:
            - "binding-secret"
            - "x509"
          redirect-uris:
            - https://*~{app-api/app-uri}/**
    requires:
      - name: app-api
  - name: expenses-db
    type: com.sap.xs.hdi-container
    parameters:
      service: hana
      service-plan: hdi-shared

Source: real mta.yaml written by cds add hana,xsuaa,mta,approuter (CAP command line tools 10.2.1); the descriptor elements are defined on SAP Help: Multitarget Applications in the Cloud Foundry Environment and in the module, resource and parameter pages of SAP-docs/btp-cloud-platform

The file has three kinds of content: global settings, three modules and two resources.

Part What the file says What it means

parameters and build-parameters at the top

enable-parallel-deployments: true, and a before-all step that runs npm ci and npx cds build --production

SAP documents enable-parallel-deployments as enabling parallel deployment of modules that have no explicit deployed-after. The before-all commands run once before any module is built, so the generated gen/ folders exist when the modules are packaged.

Module expenses-srv

type: nodejs, path: gen/srv, buildpack: nodejs_buildpack, instances: 1

The CAP server, taken from the production build. SAP lists nodejs as a module type that creates a Cloud Foundry application with Node.js runtime and the buildpack nodejs_buildpack as its default.

Module expenses-db-deployer

type: hdb, path: gen/db

A small application that pushes the generated design-time files into the HDI container. It needs the expenses-db resource. SAP lists com.sap.xs.hdi, the type that mbt derives from hdb (see the archive below), as a Cloud Foundry application with HDI content activation, with the defaults no-route and cf-task.

Module expenses

type: approuter.nodejs, path: .deploy/app-router, keep-existing-routes: true

The application router from the folder that cds add approuter wrote. SAP describes keep-existing-routes as keeping routes that were mapped by hand (cf map-route) even when the descriptors do not mention them, and recommends defining all routes in the descriptors instead.

Resource expenses-auth

org.cloudfoundry.managed-service, service: xsuaa, service-plan: application, path: ./xs-security.json

The XSUAA instance. The descriptor of scopes and role templates is passed in through path, and xsappname is composed from the org and space names.

Resource expenses-db

com.sap.xs.hdi-container, service: hana, service-plan: hdi-shared

The HDI container in SAP HANA Cloud. SAP’s resource page lists hana and hdi-shared as the defaults of this resource type, and CAP’s SAP HANA guide says the plan hdi-shared creates an HDI container.

Two mechanisms connect the parts, and both are worth understanding because they are the part of an mta.yaml that newcomers find least obvious.

  1. provides and requires. SAP’s parameters page says that one module declares a provides block, another declares a matching requires entry and reads individual values with the syntax ~{<provides-name>/<property>}, naming the provides block rather than the module. Here expenses-srv provides srv-api with the property srv-url, and the application router requires srv-api and reads ~{srv-url} as the URL of its destination. The same page says that a requires dependency between modules influences the deployment order: the provider is deployed first.

  2. Placeholders. A value written ${default-url} is a parameter that the deployment fills in. SAP’s page defines ${default-url} as ${protocol}://${default-uri}, and the default host name follows the convention ${org}-${space}-<module_name>. That is why the xsappname of the XSUAA instance, expenses-${org}-${space}, differs per org and space. The comment # must be used in xs-app.json as well in the file means that the destination name: srv-api of the requirement and the destination of the route in xs-app.json must be the same string.

The line group: destinations is written by the CAP command; the pages read for this page do not explain the keyword, so this page does not interpret it beyond noting that the property name, url and forwardAuthToken: true describe one destination for the application router.

Build for production: cds build

cds build --production compiles the model and prepares the self-contained folders that the modules point at. CAP’s build guide says that build tasks derive from the configuration and project context and that for most projects cds build --production is enough. Running it standalone is also how the CAP guide suggests inspecting what will be deployed. This is the real output in the lab copy, shortened where the command itself shortens it.

npx cds build --production
building project with {
  versions: { cds: '10.2.2', compiler: '7.2.1', dk: '10.2.1' },
  target: 'gen',
  tasks: [
    { src: 'db', for: 'hana', options: { model: [ 'db', 'srv', 'app', 'app/*', '@sap/cds/srv/outbox' ] } },
    { src: 'srv', for: 'nodejs', options: { model: [ 'db', 'srv', 'app', 'app/*', '@sap/cds/srv/outbox' ] } }
  ]
}
done > wrote output to:
   gen/db/package.json
   gen/db/src/gen/.hdiconfig
   gen/db/src/gen/.hdinamespace
   gen/db/src/gen/DRAFT.DraftAdministrativeData.hdbtable
   gen/db/src/gen/ExpenseService.Claims.hdbview
   gen/db/src/gen/ExpenseService.Claims_drafts.hdbtable
   gen/db/src/gen/ExpenseService.DraftAdministrativeData.hdbview
   gen/db/src/gen/cds.outbox.Messages.hdbtable
   gen/db/src/gen/data/sap.guide.expenses-Claims.csv
   gen/db/src/gen/data/sap.guide.expenses-Claims.hdbtabledata
   gen/db/src/gen/sap.guide.expenses.Claims.hdbtable
   gen/db/undeploy.json
   gen/srv/package-lock.json
   gen/srv/package.json
   gen/srv/srv/_i18n/i18n.json
   ... 25 more. Run with DEBUG=build to show all files.

build completed in 1117 ms

Source: real output of cds build --production (shortened by the command itself and by removing the _i18n message files); the command is described on CAP: Customizing cds build

The two tasks are the two build task types the guide lists: hana produces SAP HANA Development Infrastructure (HDI) design-time artifacts and nodejs produces the Node.js application. Both go below gen/, the default target folder for Node.js projects. The files that matter for the database are plain text that you can read:

COLUMN TABLE sap_guide_expenses_Claims (
  ID NVARCHAR(36) NOT NULL,
  createdAt TIMESTAMP,
  createdBy NVARCHAR(255),
  modifiedAt TIMESTAMP,
  modifiedBy NVARCHAR(255),
  title NVARCHAR(80),
  status NVARCHAR(1) DEFAULT 'N',
  amount DECIMAL(9, 2),
  PRIMARY KEY(ID)
)

Source: real gen/db/src/gen/sap.guide.expenses.Claims.hdbtable; the artifact types are described on CAP: Using SAP HANA Cloud for Production. The lab table is a reduced teaching version (status and amount), not the full ZEXP_CLAIM table of the ABAP pages.

The same folder holds one .hdbview per service entity (ExpenseService.Claims.hdbview selects from the table above), an .hdbtabledata file that loads the lab’s CSV data, and .hdiconfig and .hdinamespace, which the CAP guide calls technical files required by HDI. Two other generated files are worth reading once.

[
  "src/gen/**/*.hdbview",
  "src/gen/**/*.hdbindex",
  "src/gen/**/*.hdbconstraint",
  "src/gen/**/*_drafts.hdbtable",
  "src/gen/**/*.hdbcalculationview"
]

Source: real gen/db/undeploy.json; its purpose is explained on CAP: Using SAP HANA Cloud for Production

The CAP guide explains the list: an HDI deployment by default never deletes artifacts, so removing an entity from the model leaves its table and content in the database, and undeploy.json names the generated files that HDI should remove when they disappear. The guide warns never to put entries for tables (.hdbtable) in that file, because that leads to data loss for tables that are not part of the deploy set. It also warns that HDI deploys CSV data as .hdbtabledata and assumes exclusive ownership of it, so the next deployment overrides it; use CSV files only for configuration data that no application endpoint can change.

The second file is gen/db/package.json, the manifest of the database deployer. Its scripts.start runs @sap/hdi-deploy through node node_modules/@sap/hdi-deploy/deploy.js --use-hdb, and it declares engines.node as ^24, while the lab project declares >=22.12. The buildpack on your landscape decides which Node.js versions a deployer or server can use, so read the engine lines of gen/db/package.json and gen/srv/package.json before the first deployment instead of assuming the baseline of the lab.

Package the application: mbt build

The Cloud MTA Build Tool (mbt) turns mta.yaml and the built folders into one archive. The tool’s documentation describes mbt build as a one-step build that generates a temporary Makefile from the descriptor, runs the make command and packages the project into an MTA archive. Its flags include -t for the target folder and --mtar for the archive name. Its prerequisites page lists GNU Make and the module build tools. The lab README pins mbt 1.2.52, installed with npm; npm reported that the package has an install script, and the mbt command was available afterwards. The build below ran in the lab copy with mbt 1.2.52 installed locally in a separate directory, Node.js 24.21.0, and the GNU Make 3.81 that ships with macOS. The documentation names version 4.2.1 as the prerequisite; the build succeeded here with the older macOS version, but use the documented one if a build fails.

npm install mbt@1.2.52
mbt build -t gen --mtar mta.mtar
[2026-11-13 15:23:01]  INFO Cloud MTA Build Tool version 1.2.52
[2026-11-13 15:23:01]  INFO generating the "Makefile_20261113152301.mta" file...
[2026-11-13 15:23:01]  INFO done
[2026-11-13 15:23:01]  INFO validating the MTA project
[2026-11-13 15:23:01]  INFO running the "before-all" build...
[2026-11-13 15:23:01]  INFO executing the "npm ci" command...
[2026-11-13 15:23:02]  INFO executing the "npx cds build --production" command...
[2026-11-13 15:23:04]  INFO building the "expenses-srv" module...
[2026-11-13 15:23:04]  INFO executing the "npm clean-install --production" command...
[2026-11-13 15:23:04]  INFO finished building the "expenses-srv" module
[2026-11-13 15:23:04]  INFO building the "expenses-db-deployer" module...
[2026-11-13 15:23:04]  INFO executing the "npm install --production" command...
[2026-11-13 15:23:06]  INFO finished building the "expenses-db-deployer" module
[2026-11-13 15:23:06]  INFO building the "expenses" module...
[2026-11-13 15:23:06]  INFO executing the "npm install --production" command...
[2026-11-13 15:23:10]  INFO finished building the "expenses" module
[2026-11-13 15:23:10]  INFO running the "after-all" build...
[2026-11-13 15:23:10]  INFO generating the metadata...
[2026-11-13 15:23:10]  INFO generating the MTA archive...
[2026-11-13 15:23:10]  INFO the MTA archive generated at: gen/mta.mtar
[2026-11-13 15:23:10]  INFO cleaning temporary files...

Source: real output of mbt build 1.2.52 (shortened: the cds build output, the npm install summaries and the META-INF line are left out); flags from Cloud MTA Build Tool: Usage; the flag combination is the one in CAP: Deploy to Cloud Foundry

The log shows the order that the descriptor asks for: the before-all commands first (so cds build --production ran a second time, here), then one build per module, each with its own production install of its dependencies, then the archive. The archive is a file of 12,115,043 bytes for this tiny project, built in the JAR-compatible ZIP format that SAP’s page on defining multitarget application archives describes (it is not a tar file, whatever its name suggests), and the three data.zip files hold 2213, 988 and 5639 files, most of them installed dependencies. Its listing shows what the deployment service will receive:

META-INF/MANIFEST.MF
META-INF/mtad.yaml
expenses/data.zip
expenses-db-deployer/data.zip
expenses-srv/data.zip
xs-security.json

Source: the entries of the archive built above; any ZIP tool lists them, for example unzip -Z1 gen/mta.mtar (the entries for the directories are left out); the archive structure is described on SAP-docs: Defining Multitarget Application Archives

The file META-INF/mtad.yaml is the deployment descriptor that mbt derived from mta.yaml. Compared with the development descriptor it is the same model with resolved module types: nodejs and approuter.nodejs both became javascript.nodejs, hdb became com.sap.xs.hdi, and each path now names the packed module (expenses-srv, expenses-db-deployer, expenses) rather than a source folder. META-INF/MANIFEST.MF links each data.zip to its module and xs-security.json to the resource expenses-auth. Inside expenses/data.zip the application router archive contains default-env.json next to xs-app.json, exactly as generated, so review that folder before you deploy a real application. SAP’s overview page of multitarget applications lists limits that apply to such an archive: 4 GB for the archive, 1 GB for the content of a module and 1 MB for each descriptor; the page on defining archives states a maximum of 500 MB, so check the current limit before you deploy a large application.

Deploy: cf deploy and cds up

Everything above ran without an account. The step that follows needs one: it logs on to a Cloud Foundry org and space of a subaccount, where the Cloud Foundry CLI with the multiapps plugin sends the archive to the SAP Cloud Deployment service. SAP’s documentation says that the Space Developer role is required to deploy multitarget applications.

flowchart TD A["cds add hana, xsuaa, mta, approuter (once)"] --> B["mta.yaml, xs-security.json, .deploy/app-router"] B --> C["mbt build: before-all runs npm ci and cds build --production"] C --> D["gen/srv, gen/db, .deploy/app-router packed per module"] D --> E["gen/mta.mtar with META-INF/mtad.yaml"] E -- "cf deploy gen/mta.mtar -f (needs a BTP account)" --> F["SAP Cloud Deployment service"] F --> G["Creates XSUAA instance and HDI container"] F --> H["Starts db deployer, then server and application router"] G --> H H --> I["User opens the application router URL"] X["cds up runs these steps in one command"] -.-> C

Requires an SAP BTP account; not run here. The CAP guide lists the one-time preparation of the Cloud Foundry command line client and then the logon and target.

cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
cf install-plugin -f multiapps
cf login --sso
cf target

Source: CAP: Deploy to Cloud Foundry. cf login --sso is the logon with an SAP Universal ID and cf target shows or sets the org and space, as the guide states; the same logon is described in the page on Cloud Foundry and Kyma environments.

Requires an SAP BTP account; not run here. The one-command variant is cds up. The CAP guide says that it automates the steps, and that on its first run it creates a package-lock.json for all application modules so that the dependencies are frozen. Written out, the guide lists the final assembly and deployment as these two commands, which are the ones shown above for the build and the deployment.

cds up
mbt build -t gen --mtar mta.mtar
cf deploy gen/mta.mtar -f

Source: CAP: Deploy to Cloud Foundry. SAP’s description of cf deploy is on SAP Help: Multitarget Application Commands for the Cloud Foundry Environment, where -f forces the deployment without asking for confirmation about aborting conflicting processes.

The CAP guide says the process can take some minutes and ends by logging that the application was started and is available at a URL of the form org-space-application in the landscape domain. That URL belongs to the application router, which is the entry point. The same guide points out that, by default, CAP creates a role collection named admin-org-space, which an administrator must assign to a user (the page on XSUAA and identity covers assigning role collections) before the admin endpoints work. The deployed application can then be inspected in the Applications list of the space in the BTP cockpit.

Landscape-specific settings: MTA extension descriptors

Settings that differ between landscapes, such as the number of instances, do not belong in the base mta.yaml. The CAP guide shows passing an MTA extension descriptor to cds up with --overlay, and SAP documents the extension descriptor as a separate file that extends the base descriptor.

Requires an SAP BTP account; not run here.

cds up --overlay .deploy/eu10-prod.mtaext
_schema-version: 3.3.0
ID: bookshop-eu10-prod
extends: bookshop

modules:
  - name: bookshop-srv
    parameters:
      instances: 2

Source: CAP: Deploy to Cloud Foundry (the guide’s bookshop names, not the lab’s); the file type is defined on SAP-docs: Defining MTA Extension Descriptors. For the lab, the ID would be an invented name such as expenses-eu10-prod and extends would be expenses, the ID of the file above.

The database side of a deployment

When the archive is deployed, the deployment service creates the HDI container from the expenses-db resource and starts expenses-db-deployer. That module runs @sap/hdi-deploy, which reads the gen/db/src/gen files and creates or updates the tables and views inside the container, and it needs an SAP HANA Cloud database that is running in the subaccount, plus an entitlement for the hdi-shared plan. CAP’s Cloud Foundry guide lists both as prerequisites and notes that starting the database takes several minutes and, in trial accounts, has to be repeated every day. Because SAP lists no-route as a default of that module type, the deployer is not a place where users send requests.

For quick development roundtrips against a real database the CAP SAP HANA guide offers a shortcut that deploys only the database part: cds add hana --for hybrid configures a hybrid profile, cds deploy --to hana builds, creates the hdi-shared service, starts the deployer from your computer and stores the binding in .cdsrc-private.json, and cds watch --profile hybrid then runs the server locally against that database. That route also needs a Cloud Foundry logon and a running SAP HANA Cloud instance, so it was not run. The guide describes it as ad hoc deployment, and for the full application it points back to the deployment guide that this page follows.

Multitenancy: where to look

Everything so far describes a single-tenant application: one deployment, one set of users and one database container. CAP’s multitenancy guide describes the alternative: the ability to serve multiple tenants through single clusters of microservice instances while isolating the tenants' data, where tenants are the customers of a software-as-a-service (SaaS) solution. The guide says CAP supports this with the package @sap/cds-mtxs, that applications wait for tenants to subscribe before they serve any end-user request, and that the facet is added with cds add multitenancy (followed by npm install for Node.js or mvn install for Java). This page points to that guide rather than repeating it.

  • For Node.js the guide says cds add multitenancy adds a sidecar subproject at mtx/sidecar, which is a second application with its own package.json, and changes deployment descriptors such as mta.yaml; the sidecar’s engines.node in the guide is >=24.

  • For Java the guide lists the Maven dependency cds-feature-mt and a sidecar URL setting, and says schema updates of Java applications follow the Java guide.

  • To deploy, the guide prepares the project with cds add hana,xsuaa, optionally cds add portal, and cds add mta, and then runs cds up. A tenant then subscribes in its own subaccount, which has to be in the same region as the provider subaccount. On Cloud Foundry the guide says a route may need to be created and mapped by hand with cf map-route, and warns that a host name must not exceed 63 characters.

  • To update the database schema of the tenants the guide shows cds-mtx upgrade from a terminal, an MTX sidecar API call, a Cloud Foundry hook in mta.yaml, a Cloud Foundry task and a Kubernetes job.

Source: CAP: Deploy Multitenant SaaS Applications. Requires an SAP BTP account; not run here. The lab project was not made multitenant.

Kyma instead of Cloud Foundry

Everything about mta.yaml, mbt and cf deploy is specific to the Cloud Foundry environment. A project that targets the Kyma environment uses the same cds add hana,xsuaa preparation and then cds add kyma, which writes Helm charts instead of an MTA descriptor. The page on Cloud Foundry and Kyma environments covers that route and its commands, so this page does not repeat them.

What can go wrong

Symptom Likely cause What to do

mbt build does not work on Windows

The CAP guide says that Windows also needs GNU Make

Install GNU Make as the guide and the mbt documentation describe, then repeat the build.

A table or its data survives after the entity was removed from the model

HDI never deletes artifacts by default

Add the generated file pattern to undeploy.json, but never a .hdbtable entry, as the CAP SAP HANA guide warns.

Edited data in a table is reset on the next deployment

The data came from a CSV file that HDI owns exclusively

Keep CSV data for configuration that users cannot change, as the CAP SAP HANA guide advises.

The Node.js requirements of the modules differ

The generated files carry their own engines.node: ^24 for the deployer, >=22.12 in the lab

Compare gen/db/package.json and gen/srv/package.json with the buildpack versions of the landscape, as shown above.

The application URL answers that the route does not exist (multitenant only)

The subscriber’s route was not created and mapped yet

Create and map it with cf map-route, as in the CAP multitenancy guide.

The XSUAA instance has no roles

The model has no authorization annotations, so xs-security.json is empty

Add @requires or @restrict annotations and regenerate with cds compile --to xsuaa; see the XSUAA page.

Opening the root URL of the deployed application shows no index page

The development index page and Fiori preview exist only in the development profile

Add a real SAP Fiori elements or UI5 application behind the application router, as the CAP guide advises.

Summary

  • cds add hana,xsuaa,mta,approuter prepares a CAP project for Cloud Foundry once: it adds @cap-js/hana and @sap/xssec, sets auth to xsuaa in the production profile, and writes mta.yaml, xs-security.json and a .deploy/app-router folder.

  • mta.yaml describes three modules (server, database deployer, application router) and two resources (XSUAA, an HDI container), connected by provides and requires and filled in with ${...} placeholders.

  • cds build --production writes the HDI design-time files and the server to gen/; mbt build packs every module and META-INF/mtad.yaml into one mta.mtar.

  • cf deploy gen/mta.mtar -f, or the single command cds up, sends the archive to the SAP Cloud Deployment service. These steps and SAP HANA Cloud need an SAP BTP account and were not run.

  • HDI never deletes artifacts by itself, owns CSV data exclusively and can be told what to remove with undeploy.json.

  • Multitenancy, with the @sap/cds-mtxs package and an MTX sidecar, and the Kyma route are separate paths that the CAP guides document.

Try it

To do this by hand, follow the guide Package a CAP App as an MTA Archive: it builds a local MTA archive and reads the generated descriptor.