Create a Hello World Multitarget Application
- How to create a module that describes a Java application
- How to create a resource that describes your database binding
- How to create additional metadata required for the deployment
Prerequisites
- You have created a Java application
.war file. - You have an SAP BTP database configured in your subaccount and valid credentials.
- Step 1
You define the entities that have to be deployed, namely modules and resources related to other modules, in the MTA deployment descriptor. This is a YAML file that defines the contract between you as a deployable artifact provider and the SAP BTP as a deployer tool. Initially, you have to describe the metadata required for the deployment.
- Create an empty text file and name it
mtad.yaml. - Using a text editor, enter the following data in the file:
YAMLCopy
_schema-version: '3.1' parameters: hcp-deployer-version: '1.1.0' ID: com.example.demo.basic version: 0.1.0Strictly adhere to the correct indentations when working with YAML files, and do not use the tabulator character.
The example above instructs the SAP BTP to:
- Validate the Multitarget Application against the MTA specification version
3.1 - Use deploy features specific to the SAP BTP marked as version
1.0 - Deploy the Multitarget Application as a Solution with ID
com.example.demo.basic - Consider the Multitarget Application version as a version
0.1.0
- Validate the Multitarget Application against the MTA specification version
-
Create the module that describes the Java application. In the mtad.yaml, add the following data:
YAMLCopymodules: -name: example-java-app type: com.sap.java requires: - name: db-binding parameters: name: example jvm-arguments: -server java-version: JRE 7 runtime: neo-java-web runtime-version: 1The example above instructs the SAP BTP to:
- Deploy a Java application with a specific runtime, Java version, and runtime arguments
- Require a MTA resource called db-bindings, where you describe your binding data
-
Describe the database binding ID and the database credentials the Java application has to use by adding the following to the
mtad.yaml:YAMLCopyresources: - name: db-binding type: com.sap.hcp.persistence parameters: id:The example above instructs the SAP BTP to create a database binding during the deployment process.
At this point of the procedure, no database ID or credentials for your database binding have been added. The reason for this is that all the content of the
mtad.yamlso far is a target-platform independent, meaning that the samemtad.yamlcould be deployed to multiple SAP BTP subaccounts.The information about your database ID and credentials are, however, subaccount-specific. To keep the
mtad.yamltarget platform independent, you have to create an MTA extension descriptor. This file is used in addition to your primary descriptor file, and contains data that is account-specific.Security-sensitive data, for example database credentials, should be always deployed using an MTA extension descriptor, so that this data is encrypted.
Fill in the missing "type" and "runtime" parameters:
modules:
- name: example-java-app
type:
requires:
- name: db-binding
parameters:
name: example
jvm-arguments: -server
java-version: JRE 7
runtime:
runtime-version: 1 - Create an empty text file and name it
- Step 2
-
Create an empty text file and name it
dev.mtaext. -
Using a text editor, enter the following data in the file:
YAMLCopy_schema-version: '3.1' ID: com.example.demo.basic.config extends: com.example.demo.basic parameters: title: Basic Solution description: This is a sample of a basic Solution. resources: - name: db-binding parameters: id: dbalias user-id: myuser password : mypasswordThe example above instructs the SAP BTP to:
- Extend the
com.example.demo.basicMTA deployment descriptor with thecom.example.demo.basic.configMTA extension descriptor - Define the title and description for the target solution that will be visible in the SAP BTP
- Extend the db-binding resource and define within the following parameters:
- Alias of the database
- User for the database schema that you own
- Password for the database schema that you own
At this point of the procedure, the MTA deployment descriptor, MTA extension descriptor, and the Java application
.warfiles are compiled. You can now package your Multitarget Application archive and deploy it to the SAP BTP.The MTA archive contains all entities that have to be deployed. It also contains a manifest file, which links the modules and resources described into the MTA deployment descriptor file using their location in the archive. Using this data, the SAP BTP deploys the Multitarget Application archive as a solution.
- Extend the
Which of the following lines is incorrect?
_schema-version: '3.1'
parameters:
hcp-deployer-version: '1.0'
ID: Example
version: 0.1.0
modules:
- name: java-module
type: java.tomcat
parameters:
name:
destinations:
java-version: JRE 8
runtime-version: 3
provides:
- name: javabackend
requires:
- name: database
resources:
- name: MyDB
type: com.sap.hcp.persistence
parameters:
id:
user-id:
password: !sensitive
parameters-metadata:
user-id:
optional: true
consumer-optional: true
description: Database User
password:
optional: true
consumer-optional: true
description: Password for Database User -
- Step 3
-
Create an empty text file and name it
MANIFEST.MF. Explicitly use upper-case letters. -
Using a text editor, enter the following data in the file:
Manifest-Version: 1.0 Created-By: example.com Name: example.war Content-Type: application/zip MTA-Module: example-java-appThe example above instructs the SAP BTP to link the module example-java-app to the archive example.war.
CAUTION
Make sure that the
MANIFEST.MFis compliant to the JAR file specification.
-
- Step 4
MTA archives are compliant to the JAR file specification. This allows you to use commonly available tools for creating, modifying, and signing such archives. For the sake of the tutorial, we assume that you have a root directory named / where you place all the parts of the Multitarget Application before creating the archive.
- Create a folder called
META-INFin the root directory. - Place the
mtad.yamland theMANIFEST.MFfiles inside theMETA-INFdirectory. - Place the
example.wararchive inside the root directory.The MTA extension descriptor file is deployed separately from the MTA archive.
The root directory should now be structured as follows:
/example.war /META-INF /META-INF/mtad.yaml /META-INF/MANIFEST.MF -
Archive the content of the root directory in an
.mtarformat using an archiving tool capable of producing a JAR archive.
After you have created your Multitarget Application archive, you are ready to deploy it into the SAP BTP as a solution. To deploy the archive, proceed as described in Deploy a Standard Solution.
- Create a folder called