How to Overwrite variables to Payara JPA access SQL services


In this tutorial, we’ll cover how you can overwrite Payara configurations to access the services in


This tutorial assumes you have

  • A working Payara application with Java 8 or higher
  • A text editor of your choice.

Problems has a Java configuration-reader library that provides a streamlined and easy to use way to interact with a environment and those services. However, you can also use the application regularly and overwrite those configurations when you deploy your application on That is useful when you either already have one app and want to move to or keep the default configuration to run locally.


First, to use a database as a data source in Payara Micro, you’ll need to have the database already running. Once you have that in place, download the JDBC driver for the database and put it into your WEB-INF/lib directory.

In your web.xml add the following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns=""  xmlns:xsi=""

You can overwrite those configurations on the the application configuration to As shown in the configuration below.

name: app
type: "java:8"
disk: 1024
    build: mvn clean package payara-micro:bundle
    database: "db:postgresql"
        start: |
          export HOST=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".database[0].host"`
          export PASSWORD=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".database[0].password"`
          export USER=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".database[0].username"`
          export DATABASE=`echo $PLATFORM_RELATIONSHIPS|base64 -d|jq -r ".database[0].path"`
          java -jar -Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError  \
          -Dserver.database=$DATABASE \
          -Dserver.user=$USER \
          -Dserver.password=$PASSWORD \
          target/microprofile-microbundle.jar --port $PORT

Therefore, you can have the configuration or just migrate the application that already exists to