Using variable references

A variable can be referenced anywhere inside a string value of a property which supports variable references. Multiple references to system properties and environment variables can be used within the same configuration value, concatenating any number of variable references and plain text chunks. When a reference to a password alias is used, it has to expand to the whole property value and cannot be combined with any other text or variable references.

Variable references in the domain configuration

Variable references can be used inside text values in the following configuration files within the domain directory:

  • domain.xml (inside attribute values or inside text nodes that contain a configuration value)

  • logging.properties (inside property values)

Variable references in deployed applications

Variable references can be used inside text values also in the following places within deployed applications and modules:

  • Package descriptors:

    • web.xml / glassfish-web.xml

    • ejb-jar.xml / glassfish-ejb-jar.xml

    • application.xml / glassfish-application.xml

    • glassfish-resources.xml

  • Framework descriptors:

    • persistence.xml

    • faces-config.xml

  • In the annotations:

    • @EJB, @WebService, @Stateless, @Stateful, @Singleton, @ActivationConfigProperty, @DataSource, @WebServlet

  • In JNDI lookups inside an application

  • In pre and post boot command files.

  • In JVM Options.

  • In the payara-expression-config.properties file.

Examples

Here are several examples of where you can use variable references:

Within an annotation

@DataSourceDefinition(name="java:global/ExampleDataSource",
      className="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource",
      user="${mysql.user}",
      password="${ALIAS=mysql-db-password}",
      databaseName="${ENV=MYSQL_DBNAME}",
      serverName="localhost"
   )

Within a web.xml descriptor

<data-source>
     <name>java:global/ExampleDataSource</name>
     <class-name>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</class-name>
     <server-name>localhost</server-name>
     <port-number>3306</port-number>
     <database-name>${ENV=MYSQL_DBNAME}</database-name>
     <user>${mysql.user}</user>
     <password>${ALIAS=mysql-db-password}</password>
</data-source>

Multiple variable references combined in a single value withing the domain.xml

<domain log-root="${com.sun.aas.instanceRoot}/${ENV=STAGE_NAME}/logs">

Within a pre or post boot command file

set configs.config.server-config.http-service.virtual-server.server.default-web-module=${ENV=deployed-app-name}
set configs.config.server-config.network-config.protocols.protocol.http-listener-1.security-enabled=${ENV=security-enabled}

Within a logging.properties file

handlers=${ENV=CONSOLE-HANDLER}
handlerServices=${ENV=SYS-LOG-HANDLER}

Within a payara-expression-config.properties file

The payara-expression-config.properties config source is only available in Payara Server
fish.payara.example.system=${java.home}
fish.payara.example.env=${ENV=PATH}
fish.payara.example.password=${ALIAS=secret}
fish.payara.example.multiple=property containing both an ${ENV=envProperty} and a ${sysProp}