SAP Guide: Package a CAP App as an MTA Archive

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

Checked on 2026-11-13 against CAP Node.js 10.2 (@sap/cds 10.2.2, @sap/cds-dk 10.2.1), Cloud MTA Build Tool (mbt) 1.2.52, GNU Make 3.81 and Node.js 24.21.

What you build

This is a teaching model built with CAP. It is not SAP S/4HANA or SAP SuccessFactors and does not reproduce their screens.

You take a small expense-claim service and prepare it for SAP BTP without going there. The CAP command line writes a deployment descriptor, mta.yaml, that names the parts of the application (a server, a database deployer) and the services it needs (a SAP HANA Cloud database container and an XSUAA login service). You read that file, and then the Cloud MTA Build Tool packs everything into one archive, an MTA archive (.mtar), on your own computer. You open the archive and read the descriptor that deployment would use. Nothing is deployed: no Cloud Foundry login, no SAP BTP account and no SAP HANA Cloud database are involved.

Terminal that prints the start of META-INF/mtad.yaml from the archive gen/claims-mta.mtar, with the modules claims-mta-srv and claims-mta-db-deployer

Before you start

  • No account is needed: the tools install from the public npm registry without signing in. Installing @sap/cds-dk and @sap/cds means accepting the SAP Developer License Agreement, version 3.2, which the packages state themselves; mbt is licensed under Apache-2.0. The mbt package downloads the program file of the build tool from a public release page of the project when npm installs it, which needs no login either. The lab README names the licenses.

  • Install Node.js 22.12 or newer. node -v prints the version.

  • Install GNU Make. macOS and Linux usually have it already (make --version tells); on Windows install it as well, because the CAP guide for Cloud Foundry asks for it next to mbt.

  • You need a tool that reads ZIP files for the last steps. The command unzip is used below; an MTA archive is a ZIP file.

  • Use a code editor such as Visual Studio Code, and a terminal.

  • Read Deploying CAP: HANA, XSUAA and MTA first, or at least know what a deployment descriptor is. The CAP project here is built the way the guide Your First CAP Service builds its project; if the editor or the cds command is new to you, start there. The screen map of that guide labels the regions of the editor used here.

  • The figures are drawings of the editor and the terminal, not screenshots. A highlighted box with a number marks the file, the line or the command of the step with the same number. The file names and the sizes in the archive come from one run; yours may differ in small details such as time stamps and file sizes.

Steps

Prepare the tools and the project

  1. Install the two command line tools once: cds for CAP and mbt for the build. Then ask each for its version, and check that make exists:

    npm install --global @sap/cds-dk mbt@1.2.52
    mbt --version
    make --version | head -n 1

    mbt --version answers Cloud MTA Build Tool version 1.2.52. If it prints nothing, see the table at the end.

  2. Create the project. The option --nodejs chooses the JavaScript runtime of CAP:

    cds init claims-mta --nodejs
  3. Go into the folder and install the dependencies. Open the folder in your editor (in Visual Studio Code, code .).

    cd claims-mta
    npm install
    Terminal that checks the tools and creates the project: mbt --version prints Cloud MTA Build Tool version 1.2.52 and make --version prints GNU Make 3.81, cds init claims-mta --nodejs prints Successfully initialized CAP project, and npm install in the new folder ends with found 0 vulnerabilities; callout 1 marks the two version checks, callout 2 the cds init command and its answer, callout 3 the npm install

Describe a small service

The packaging works on any CAP project; a small one keeps the files short. The model is the claim from the first guide, with its own names.

  1. Create the file db/schema.cds. It imports the building blocks cuid (a generated key ID) and managed (the fields createdAt, createdBy, modifiedAt and modifiedBy) and describes the entity Claims:

    using { cuid, managed } from '@sap/cds/common';
    
    namespace sap.guide.claims;
    
    entity Claims : cuid, managed {
      title  : String(80);
      status : String(1) default 'N';
      amount : Decimal(9,2);
    }
  2. Create the file srv/claim-service.cds. The service ClaimService offers the entity to outsiders as an OData service:

    using sap.guide.claims as db from '../db/schema';
    
    service ClaimService {
      entity Claims as projection on db.Claims;
    }
  3. Create the folder db/data and in it the file sap.guide.claims-Claims.csv. The name is the namespace, a dash and the entity name. CAP loads the file into the database when the server starts, and the build later turns it into SAP HANA content:

    ID,title,status,amount
    11111111-1111-1111-1111-111111111111,Train ticket,N,45.50
    Visual Studio Code with the claims-mta project: the editor shows srv/claim-service.cds, in which the service ClaimService exposes the entity Claims as a projection on db.Claims; callout 4 marks db/schema.cds in the explorer, callout 5 marks the service file and callout 6 marks the CSV file sap.guide.claims-Claims.csv in db/data

Add the deployment files

  1. Ask CAP for the three facets in one command. mta writes the deployment descriptor mta.yaml, hana prepares the project for SAP HANA Cloud as the production database and xsuaa prepares it for XSUAA logins:

    cds add mta,hana,xsuaa

    The command lists the three facets and changes the project in four ways. It writes mta.yaml. It writes xs-security.json, the description of the roles and scopes of the application; the model has no authorization rules, so the file is real but empty ({"scopes": [], "attributes": [], "role-templates": []}). In package.json it adds the dependencies @cap-js/hana and @sap/xssec, and the development dependency @sap/cds-dk, which the build needs. It also adds a cds block that sets the login to xsuaa in the production profile only. This command only edits files: it connects to nothing.

  2. Check that development has not changed. A CAP profile is a named set of settings, and cds env prints the setting that is in effect. Ask for the login and the database, with and without the profile production:

    cds env get requires.auth.kind
    cds env get requires.auth.kind --profile production
    cds env get requires.db.kind
    cds env get requires.db.kind --profile production

    Without the profile the answers are mocked and sqlite, the development settings you used before. With --profile production they are xsuaa and hana. The same project is therefore two applications: the one on your computer and the one that the archive will start in the cloud.

    Terminal: cds add mta,hana,xsuaa prints Adding facet for mta, xsuaa and hana and Successfully added features to your project; cds env get requires.auth.kind prints mocked and, with the profile production, xsuaa; cds env get requires.db.kind prints sqlite and, with the profile production, hana; callout 7 marks the cds add command and callout 8 marks the four cds env commands

Read the deployment descriptor

  1. Open mta.yaml. This is the complete file that cds add wrote, unchanged:

    _schema-version: 3.3.0
    ID: claims-mta
    version: 1.0.0
    description: "A simple CAP project."
    parameters:
      enable-parallel-deployments: true
    build-parameters:
      before-all:
        - builder: custom
          commands:
            - npm ci
            - npx cds build --production
    modules:
      - name: claims-mta-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: claims-mta-auth
          - name: claims-mta-db
    
      - name: claims-mta-db-deployer
        type: hdb
        path: gen/db
        parameters:
          buildpack: nodejs_buildpack
        requires:
          - name: claims-mta-db
    
    resources:
      - name: claims-mta-auth
        type: org.cloudfoundry.managed-service
        parameters:
          service: xsuaa
          service-plan: application
          path: ./xs-security.json
          config:
            xsappname: claims-mta-${org}-${space}
            tenant-mode: dedicated
            oauth2-configuration:
              credential-types:
                - "binding-secret"
                - "x509"
      - name: claims-mta-db
        type: com.sap.xs.hdi-container
        parameters:
          service: hana
          service-plan: hdi-shared

    Source: real mta.yaml written by cds add mta,hana,xsuaa (CAP command line tools 10.2.1); the descriptor elements are defined on SAP Help: Multitarget Applications in the Cloud Foundry Environment

    A multitarget application (MTA) is one application made of several parts that are built and deployed together. The file lists modules (the parts that run) and resources (the services they need, which the platform creates). The next steps read it from the top.

  2. Read the header, lines 1 to 12. ID and version name the application. The before-all block under build-parameters holds two commands that mbt runs once, before it builds any module: npm ci installs the exact versions of package-lock.json, and npx cds build --production turns the CDS model into the folders gen/srv and gen/db that the modules point at.

  3. Read the module claims-mta-srv (line 14 on). It is the CAP server: type: nodejs, built from gen/srv, started with the buildpack nodejs_buildpack as one instance. It provides a value named srv-api (its own URL, written as ${default-url}, a placeholder that the platform fills in) so that other modules, such as an application router, could find it, and it requires the two resources claims-mta-auth and claims-mta-db. A requires entry also means that the platform creates the resource before it starts the module.

  4. Read the module claims-mta-db-deployer (line 30 on). Its type hdb and its path gen/db say that it is a small application whose only job is to push the generated database files into the database container. It requires claims-mta-db.

    Visual Studio Code with mta.yaml open, showing the file down to the end of the modules part: the header with the ID claims-mta and the before-all build step that runs npm ci and npx cds build --production is marked by callout 10, the module claims-mta-srv of type nodejs with the path gen/srv, which provides srv-api and requires claims-mta-auth and claims-mta-db, by callout 11, and the module claims-mta-db-deployer of type hdb with the path gen/db by callout 12
  5. Read the resource claims-mta-auth (the line resources: and below). Its type org.cloudfoundry.managed-service and the pair service: xsuaa and service-plan: application ask the platform for an XSUAA instance. path: ./xs-security.json hands it the file that cds add xsuaa wrote, and xsappname is the application name that XSUAA knows, made unique per organization and space by the placeholders ${org} and ${space}.

  6. Read the resource claims-mta-db. The type com.sap.xs.hdi-container with service: hana and service-plan: hdi-shared asks for an HDI container: a private schema inside SAP HANA Cloud that the database deployer fills.

    Visual Studio Code with mta.yaml open, showing the file from the line resources on, drawn with its own line numbers: the resource claims-mta-auth of type org.cloudfoundry.managed-service with the service xsuaa and the file xs-security.json is marked by callout 13, and the resource claims-mta-db of type com.sap.xs.hdi-container with the service hana and the plan hdi-shared by callout 14

    The figure shows the file from the line resources: on; its line numbers start at 1 for that part.

Build the archive

  1. In the terminal, in the project folder, build the archive. -t gen puts the result in the folder gen, and --mtar names the archive:

    mbt build -t gen --mtar claims-mta.mtar
  2. Read the log. mbt first runs the before-all commands of the descriptor (npm ci, then cds build --production, which prints the files it wrote below gen). Then it builds each module in the order of the descriptor: for each one it installs the production dependencies of that module and packs the result. The log of mbt and of the commands it starts is long, because it prints the output of npm and of the CAP build; the figure keeps the lines of mbt itself and leaves out the lines that hold paths.

  3. The last lines name the archive: the MTA archive generated at: gen/claims-mta.mtar. The file is a few megabytes, mostly the installed Node.js packages of the two modules.

    Terminal: mbt build -t gen --mtar claims-mta.mtar prints the build log, shortened to its main lines: the before-all build runs npm ci and npx cds build --production, then the modules claims-mta-srv and claims-mta-db-deployer are built, the metadata and the archive are generated and the last lines say that the MTA archive was generated at gen/claims-mta.mtar; callout 15 marks the command, callout 16 the before-all and module build lines and callout 17 the line that names the archive

    Source: Cloud MTA Build Tool: Usage; the flag combination is the one in CAP: Deploy to Cloud Foundry

Look inside the archive

  1. List the entries of the archive. -Z1 prints only the names; the names that end with a slash are folders:

    unzip -Z1 gen/claims-mta.mtar
    unzip -p gen/claims-mta.mtar META-INF/MANIFEST.MF

    There is one data.zip per module (the packed server and the packed database deployer), the file xs-security.json for the XSUAA resource, and a META-INF folder with two descriptions. The second command prints MANIFEST.MF, which says which entry belongs to which module or resource.

    Terminal: unzip -Z1 gen/claims-mta.mtar lists META-INF/, META-INF/MANIFEST.MF, META-INF/mtad.yaml, claims-mta-db-deployer/, claims-mta-db-deployer/data.zip, claims-mta-srv/, claims-mta-srv/data.zip and xs-security.json, and unzip -p gen/claims-mta.mtar META-INF/MANIFEST.MF prints the manifest, which ties each data.zip to its module and xs-security.json to the resource claims-mta-auth; callout 18 marks the file list
  2. Print the start of the deployment descriptor META-INF/mtad.yaml. mbt derived it from mta.yaml:

    unzip -p gen/claims-mta.mtar META-INF/mtad.yaml | head -n 25

    It is the same model with resolved details: the module type nodejs became javascript.nodejs, hdb became com.sap.xs.hdi, and each path now names the packed module (claims-mta-srv) instead of a source folder (gen/srv). The before-all commands and the build-parameters stay in the file as a record; they were used on your computer and play no part in the cloud. This is the file that the deployment service would read, and it is the figure at the top of this page.

Check the result

  • mbt build ended without a line that starts with ERROR, and the folder gen holds claims-mta.mtar.

  • unzip -Z1 gen/claims-mta.mtar lists META-INF/mtad.yaml, one data.zip for claims-mta-srv, one for claims-mta-db-deployer and xs-security.json.

  • mtad.yaml names two modules and two resources, the same as mta.yaml.

Nothing was deployed, so there is no running application. This is what the next step, deployment, would do, and it needs an SAP BTP account, so it is described and not run. Requires an SAP BTP account; not run here. The CAP guide for Cloud Foundry says that the archive is deployed with the Cloud Foundry command line client and its multiapps plugin, after a login and the choice of an organization and space: cf deploy gen/claims-mta.mtar -f sends it to the SAP Cloud Deployment service (the guide’s example names the file mta.tar; the file name is only what you gave --mtar). That service reads mtad.yaml, creates the XSUAA instance and the HDI container that the two resources ask for, uploads the packed modules, runs the database deployer so that the tables and views of the model exist in the container, and starts the server with both services bound to it. The page Deploying CAP: HANA, XSUAA and MTA walks through that step with its commands. The archive you built is the same kind of file; the difference is that this project has no application router and no user interface.

Variations

  • Check that the development setup still works. The packaging changed only files that development ignores. Add the test dependency with npm install --save-dev @cap-js/cds-test, create the file test/service.test.js and run npm test:

    import cds from '@sap/cds'
    import { test } from 'node:test'
    import assert from 'node:assert'
    
    const { GET } = cds.test(import.meta.dirname + '/..')
    
    test('lists the claim from the CSV file', async () => {
      const { data } = await GET('/odata/v4/claim/Claims')
      assert.strictEqual(data.value.length, 1)
      assert.strictEqual(data.value[0].title, 'Train ticket')
    })

    The test starts the service with the development settings, so it uses SQLite and the mocked login, and reads the claim from the CSV file. The run prints ℹ pass 1 and ℹ fail 0.

  • Read the generated database files. After the build the folder gen/db/src/gen holds the table sap.guide.claims.Claims.hdbtable (COLUMN TABLE sap_guide_claims_Claims, with amount DECIMAL(9, 2)) and the view ClaimService.Claims.hdbview that selects from it. The database deployer hands these files to SAP HANA Cloud.

What can go wrong

Symptom Cause Fix

mbt --version prints nothing and the command ends normally

npm skipped the install script of mbt, which downloads the program file; without it the command does nothing. Produced here with npm install --ignore-scripts. Newer npm versions block install scripts until you allow them.

Run npm rebuild --global mbt (npm rebuild mbt for a project install). Then mbt --version prints the version.

The build stops in the before-all step with an ERROR line that ends in exit status 1, and npm explains that npm ci can only install with an existing package-lock.json

The before-all command npm ci needs a package-lock.json, and the project has none.

Run npm install in the project folder, which writes the file, and build again.

The build stops with ERROR the "./xs-security.json" path does not exist in the MTA project location

The resource claims-mta-auth points at ./xs-security.json, and the file was deleted or never written.

Run cds add xsuaa again, or restore the file.

mbt build fails because make is not found

GNU Make is not installed (not produced here; macOS and Linux have it).

Install GNU Make, as the CAP guide asks for Windows.

Clean up

The build writes only into the project folder. Delete the folder gen (it holds the archive and the generated folders) when you no longer need it; cds build and mbt build write it again. The folder claims-mta is yours to keep. Nothing was created outside your computer.