WAS v8.5 > Administering applications and their environment > Administering the Liberty profile > Administering the Liberty profile manually > Using includes, variables, and Ref tags in configuration files
Using variables in configuration files
We can use variables in the configuration to avoid hard coding values that might not be appropriate when the configuration is reused in different environments. Variables can be defined by setting a property in any of the following places:
- in the server configuration file, or an included file
- in bootstrap.properties
- on the ws-launch.jar command script used to start the server
Best practice: Variables specific to a particular server, for example port numbers, are usually specified in bootstrap.properties, allowing the server.xml to be shared across multiple servers while keeping those values different in each server. Variables that are shared across a group of servers, for example database configuration for a particular host, is better specified in an xml file included into the parent configuration file.
- Specify a variable in a configuration file.
Variables defined in the configuration files are scoped to the configuration elements by which they are used. For example, the following code fragment creates a variable called updateTrigger_var to be used in applicationMonitor configuration elements:
< applicationMonitor updateTrigger_var="mbean" />
To create a variable used in a particular configuration instance (such as an application or resource entry), you must also specify the instance identifier. For example:< httpEndpoint id="defaultHttpEndpoint" HTTP_default_var="8889" />
- Specify a variable in bootstrap.properties.
Variables defined in bootstrap.properties are not scoped to particular configuration elements. You enter the variables as key-value pairs. For example:
HTTP_default_var=8006
- Specify a variable on the ws-launch.jar command script.
Variables defined on the Java™ command are not scoped to particular configuration elements. You enter the variables as Java system properties. For example:
java -DHTTP_default_var=8008 -jar ws-launch.jar myServer
- Use a defined variable in the configuration.
The variable substitution syntax is ${variable_name}. For example, to use the HTTP_default_var variable, add the following code fragment to the configuration file:
< httpEndpoint id="defaultHttpEndpoint" httpPort="${HTTP_default_var}"> </httpEndpoint>
- Use variable element in the configuration
We can use the variable element to define a variable globally in the server configuration. If the same variable is defined in an included file, it is overridden by the one in server.xml . For example, to use the variable element, add the following code fragment to the configuration file:
< variable name="HTTP_default_var" value="8889" />
- Override inheritable attributes in the configuration
We can override the default values of inheritable attributes in the configuration. The inheritable attributes are listed on the Liberty profile: Configuration elements in server.xml page with an Inherits type. For example, the onError attribute is one of inheritable attributes. We can define a variable name for the onError attribute globally by either setting it in the bootstrap.properties or server.xml file with a variable element. If the same variable name is specified in both files, the value in server.xml is used. If the attribute is not explicitly set in either of two files, it uses the default value. If an invalid value is set to the inheritable attribute, the attribute value falls back to the global value defined in bootstrap.properties or server.xml file or the default value if not defined at the global level.
Another example is logging properties in the Liberty profile. See Liberty profile: Trace and logging.
Parent topic: Using includes, variables, and Ref tags in configuration files
|