Environment variables to substitute values in context.xml


I should set environment variables for tomcat process or for IDE (IntelliJ) process to substitute values in context.xml? Connection data from context.xml used by Cuba studio plugin to connect to DB? Or just Tomcat instance?


CUBA Studio connects to the database when performing the following operations: generating database scripts, performing data schema check before starting CUBA Application, executing “Create database”, “Update database”.
So if you need to hide the password from the build.gradle - you need to set environment variables for the IDE process (or globally).

Tomcat server used for debug also needs to know connection parameters to the database. So you need to set environment variable(s) also for Tomcat, or globally on the developer machine.

Also note that CUBA 7.2 has implemented the following improvements which made easier to use environment variables for connection to the database:

  1. New projects don’t use data source configured in context.xml anymore. Database connection parameters are not specified through application properties.
    Connecting to Databases - CUBA Platform. Developer’s Manual

  2. And application properties can now be taken from the environment variables: Application Properties - CUBA Platform. Developer’s Manual

Thank you!

But I still have problem, when I define datasource properties in app.properties in core module, I leave it blank:
cuba.dataSource.username =
cuba.dataSource.password =
and define env variable in shell before starting IDE
set cuba.dataSource.username=username
set cuba.dataSource.password=password
When debug session with tomcat starts, I see configuration in HikariCP config defined in shell. But when IDE try to update database (task Check cuba database in run config) I get “Database server connection error” in IDE, and run process stops. If I remove Check database task then tomcat starts successfull. I cannot update database when DB password not defined in sources?

To make Create Database and Update Database actions work, you need to define placeholder as follows in the app.properties:


And then define environment variables: ORACLE_DB_HOST and ORACLE_PASSWORD.
See this recently completed ticket: CreateDb/UpdateDb should support placeholders in a application properties file · Issue #137 · cuba-platform/cuba-gradle-plugin · GitHub

Unfortunately Studio does not currently support placing database connection parameters to environment variables with such its functions as “Generate Database Scripts” and internal checks performed before CUBA Application run configuration is run. So you won’t be able to generate update scripts without putting actual values to the app.properties.
I’ve created a Studio ticket to support that: https://youtrack.cuba-platform.com/issue/STUDIO-8458

3 posts were split to a new topic: Setting database params from env variables not working as intended

@albudarov is it possible to enhace the behavior with environment variables from Cuba Run/Debug Configaration?

Enhance in which way?

Now task “Check CUBA database” (believe “Create database” and “Update database” too) does not respect environment variables which was added in Cuba Run/Debug Configaration.
It would be very helpful to respect these variables.

All these tasks are able to use global environment variables since Studio 15. (Documentation: CUBA Studio User Guide).

I’m afraid that CUBA Studio will no receive any further improvements. The active development is now performed for the Jmix Studio.