WebSphere Tutorial · WebSphere Liberty · Lesson 6 of 23

Configuration Files and Variables

Splitting Liberty configuration with includes and configDropins, and supplying environment-specific values through variables.

Members can save this page, take notes and track progress. See membership · Sign in

Variables

Values that differ by environment are variables, written ${name}:

<variable name="db.host" defaultValue="localhost"/>
<dataSource jndiName="jdbc/orders">
  <properties.postgresql serverName="${db.host}" databaseName="orders" user="${env.DB_USER}" password="${env.DB_PASSWORD}"/>
</dataSource>

Variables can come from <variable> elements, bootstrap.properties, server.env, environment variables (${env.NAME}), or files in a variables directory (handy for Kubernetes Secrets mounted as files).

Splitting configuration

  • <include location="datasources.xml"/> pulls in another file.
  • Files in configDropins/defaults/ load first; files in configDropins/overrides/ load last and win, a clean way to adjust an image's configuration per environment without editing server.xml.
  • Encode passwords with securityUtility encode if they must live in files, or better, keep them out of files.
Resolving ${variables} from several sourcesTry it yourself
import re

sources = [                                   # later sources override earlier ones in this simulation
    ("server.xml <variable> defaults", {"db.host": "localhost", "http.port": "9080"}),
    ("bootstrap.properties", {"http.port": "9081"}),
    ("environment variables", {"db.host": "orders-db.prod.internal"}),
]
values = {}
for name, vals in sources:
    values.update(vals)

template = 'serverName="${db.host}" httpPort="${http.port}"'
print(re.sub(r"\$\{([^}]+)\}", lambda m: values[m.group(1)], template))

Output

serverName="orders-db.prod.internal" httpPort="9081"

Test yourself

Where would you put a file that overrides an image's server.xml for one environment?

  1. dropins/
  2. configDropins/overrides/
  3. logs/
  4. apps/
Show answer

Answer: configDropins/overrides/

Override files load last, after server.xml.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake