Goal
In this tutorial, we’ll cover how you can overwrite Jakarta EE/MicroProfile configurations to access the services in Platform.sh.
Preparation
This tutorial assumes you have:
- A working Jakarta EE/MicroProfile application with Java 8 or higher
- A text editor of your choice.
Problems
Platform.sh has a Java configuration-reader library that provides a streamlined and easy to interact with a Platform.sh environment and its services. However, you can also use the application regularly and overwrite those configurations when you deploy your application on Platform.sh. That is useful when you either already have one app and want to move to Platform.sh or keep the default configuration to run locally.
Steps
For MicroProfile/Jakarta EE the configurations and settings are set by MicroProfile Configuration. It is as a convention and not as standard, which by default it uses the microprofile-config.properties
file where you can set the settings and overwrite it. To have a Jakarta NoSQL application that connects a MongoDB database locally, the configuration will be like this:
document=document
document.database=conferences
document.settings.jakarta.nosql.host=localhost:27017
document.provider=org.eclipse.jnosql.diana.mongodb.document.MongoDBDocumentConfiguration
You can overwrite those configurations in platform.app.yaml
, the application configuration file for Platform.sh:
name: app
type: "java:8"
disk: 800
hooks:
build: mvn -U -DskipTests clean package payara-micro:bundle
relationships:
mongodb: 'mongodb:mongodb'
web:
commands:
start: |
export MONGO_PORT=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".mongodb[0].port"`
export MONGO_HOST=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".mongodb[0].host"`
export MONGO_ADDRESS="${MONGO_HOST}:${MONGO_PORT}"
export MONGO_PASSWORD=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".mongodb[0].password"`
export MONGO_USER=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".mongodb[0].username"`
export MONGO_DATABASE=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".mongodb[0].path"`
java -jar -Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError -Ddocument.settings.jakarta.nosql.host=$MONGO_ADDRESS \
-Ddocument.database=$MONGO_DATABASE -Ddocument.settings.jakarta.nosql.user=$MONGO_USER \
-Ddocument.settings.jakarta.nosql.password=$MONGO_PASSWORD \
-Ddocument.settings.mongodb.authentication.source=$MONGO_DATABASE \
target/heroes-microbundle.jar --port $PORT
Therefore, you can have the configuration or just migrate the application that already exists to Platform.sh.