Goal
This “how to” guide will explain about create multiple applications with applications.yaml
file with Java.
Assumptions
-
You either have a Java application, and you want to run at Platform.sh or you already have a Java application running at Platform.sh
-
A text editor of your choice.
Steps
Create a .platform/applications.yml
file at the root directory of your project, this file will have the each application’s configuration. In this file, we’re going to use YAML’s built-in “anchors” to share configuration typically found in a .platform.app.yaml
file between multiple applications.
When we talk about YAML achor
there are two important points:
-
The anchor ‘&’ which defines a chunk of configuration
-
The alias ‘*’ used to refer to that chunk elsewhere
In the code below, we define the anchorappdef
that contains the settings of the first application, app
, and we use the alias for the second application, app2
. That becomes the basis of the first application, which we can then overwrite with information, such as the app’s unique name.
- &appdef
name: app
type: 'java:8'
disk: 1024
source:
root: app
hooks:
build: mvn clean install
mounts:
'server/':
source: local
source_path: server_source
web:
commands:
start: |
cp target/dependency/webapp-runner.jar server/webapp-runner.jar
cp target/tomcat.war server/tomcat.war
cd server && java -jar -Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError webapp-runner.jar --port $PORT tomcat.war
-
<<: *appdef
name: app2
source:
root: app2
web:
commands:
start: |
cp target/dependency/webapp-runner.jar server/webapp-runner.jar
cp target/tomcat.war server/tomcat.war
cd server && java -jar -Xmx$(jq .info.limits.memory /run/config.json)m webapp-runner.jar --port $PORT --path app2 tomcat.war