How to inject System properties into JBoss ?

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

JBoss AS 7

If you are running JBoss AS 7 you can either add your system property directly into the configuration file or use the CLI. Let's see first the configuration file approach:

In the Standalone mode,  the change will go into standalone.xml
In the Domain mode, the change will go into domain.xml

Add the system-properties  element right after the extensions element.

<extensions>
  . . .
</extensions>

<system-properties>
        <property name="my.project.dir" value="/home/francesco"/>
</system-properties>

System properties can be read/written as well using the CLI.

$ ./bin/jboss-cli.sh  
[standalone@localhost:9999 /] /system-property=foo:add(value=bar)
[standalone@localhost:9999 /] /system-property=foo:read-resource
{
    "outcome" => "success",
    "result" => {"value" => "bar"}
}

JBoss AS 4-5-6

One cool way to add a list of System properties to JBoss is the Properties MBean Service.
In the deployment folder look for "properties-service.xml". (if you don't have it in your release you can create it at any time) :

Now add your properties either in the URLList Attribute or in the Properties Attribute:

<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService" 
     name="jboss:type=Service,name=SystemProperties">
 
    <attribute name="URLList">
      http://somehost/some-location.properties,
      ./conf/somelocal.properties
    </attribute>

    <attribute name="Properties">
       property1=This is the value of my property
       property2=This is the value of my other property
    </attribute>
   
</server>

As you can see the The "URLList" is a comma-separated list of URL strings from which to load properties file-formatted content while the "Properties" is a specification of multiple property name=value pairs

Now you can access your properties with standard:

System.getProperty("property1");

Related articles available on mastertheboss.com

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

Follow us on Twitter