Friday, July 2, 2010

How to set System properties in JBoss


Target Audience: Beginners
Most of the times, we have to deploy our application in many environments for testing before going to production or live. We might have configuration values which need to be set in System Properties and these configuration might change based on the environment. We set System propertis in run.conf , run.sh or run.bat files with -D prefix
E.g: If we want to Set System property with key ‘myKey’ and with value ‘myValue” then we do something like JAVA_OPTS="XXXXXX -DmyKey=myValue.

JBoss give a rich way to load system properties. System properties can also be provided using the System Properties Service. This service allows you to specify one or more system propertis as key value pair or through loading one or more properties file. The Service configuration file can be found in the server/xxx/deploy/properties-service.xml.

The following section describes hoe to set one or more system properties as Key Value pairs.

<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
myKey1=myValue1
myKey12=myValue2
</attribute>
</mbean>

The Properties attribute section configures properties directly in the service
configuration. Properties must be specified as a name/value pair on a separate
line.

The following section describes hoe to set system properties through loading one or more files.

<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="URLList">
http://localhost/myapp-config.properties, ./conf/myweb-config.properties
</attribute>
</mbean>

The URLList attribute section refers to properties files that contain system properties.
You can provide a URL(http://localhost/myapp-config.properties) or a directory which is relative(./conf/myweb-config.properties) to the root of the server configuration.
Multiple entries should be separated with commas as shown above.

Hope this tutorial helps you.

No comments:

Post a Comment