How to use environment variables in WildFly configuration (standalone.xml or host.xml)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

Passing environment variables to WildFly or JBoss AS has been traditionally an issue which has been often solved turning the environment variables into Java System Properties. For example:

$ export LOGPATH=/home/jboss/log

$ ./ -DlogPath=LOGPATH

 Later on you could use the System Property with a standard Bean Shell expression, as in this example:

<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
 <param name="File" value="${logPath}/server.log"/>
   . . . .  

 Luckily there is an easier step which allows us to use directly our environment variables, without turning them into System Properties: just use the env pattern in the Bean Shell expression. See the following example:

<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
 <param name="File" value="${env.LOGPATH}/server.log"/>
   . . . .  

 The env pattern is quite flexible, as you can use it in conjunction with System Properties and a default fall back expression. See the following example:

<interface name="public">
    <inet-address value="${jboss.bind.address,env.HOST:}"/>

In the above example, at first the Java system property jboss.bind.address is evaluated and, if included, used. Otherwise the env.HOST Environment variable is checked. If none is used, the interface is assigned the fallback expression


Related articles available on

JBoss MBeans POJO

JMX MBean services are the core building blocks of the JBoss Appl

How to a dump of JNDI tree with JMX console ?

#2 JBoss Howto. This is the recipe of the day

How to configure JBoss to bind to a different IP ?

  If you want to change the jboss.bind.address property use the 

How to shut down JBoss from remote ?

JBoss recipe of the day

How to create multiple instances of an Mbean?

  Supposing you need two instances of an MBean, let's say one fo

JBoss classloader issues

By default JBoss (prior to version 3.2) uses a flat class loading