Java/JBoss EAP 6.1+ – Power to the Properties

Posted: October 28th, 2013 | Author: | Filed under: Technology | Tags: , | 1 Comment »

System Properties

Comparable to Properties files included in applications, the Java JVM maintains a set of Properties for its own configuration. System properties include information about the current working environment, current user, and version of the JVM, but can also store values from users and application. The JBoss EAP 6 server provides several methods for defining system properties including passing values as command line arguments during server initialization, providing values within external properties files, and by defining values within the standalone.xml/domain.xml configuration files. We will discuss how each of these methods can be configured and ultimately utilized within applications deployed on the JBoss server.

System properties available to the JBoss server can be listed by using either the Management Web Console or the CLI. To view system properties through the Management Console, under the Status navigation section on the Runtime page, expand Platform and then select Environment. Through the JBoss CLI, they can be viewed by executing the following query:

/core-service=platform-mbean/type=runtime/:read-attribute(name=system-properties)

System properties can be passed in as command line arguments during the initialization of the JBoss server using the traditional –Dproperty syntax. For example, to set a property key of prop1 to a value of jboss when using Standalone mode in a Linux environment, execute the following:

./standalone.sh –Dprop1=jboss

This value can be verified using one of the querying methods above, but also using the sample application. Since prop1 is a key value in each of the classpath resources from the earlier sections, the application will search for a corresponding value in the JVM system properties and print out the result.

Instead of specifically passing in a set of command line arguments at JBoss startup, a properties file can be used instead to conveniently define a set of property key/value pairs. This method replaces the properties service MBean provided in previous versions of JBoss. An example properties file has been provided in the support folder called standalone-jboss-properties.properties to demonstrate this method. External properties are specified by setting the –P flag when calling the standalone.sh/domain.sh startup scripts. This method also supports the inclusion of multiple property files. To use the example properties file, run the following command:

./standalone.sh –P <project_root>/support/ standalone-jboss-properties.properties

System properties passed in through the –P flag have a higher precedence than those specified as command line arguments and can be verified by specifying both options when starting the JBoss container and launching the sample application.

The final method allows properties to be defined within the JBoss configuration file (standalone.xml/domain.xml file). This can be done through the Management Web Console or through the CLI. To set system properties through the Management Console, navigate to the Profile page, and under general configuration, select System Properties. The property names and values can be set by clicking the Add button. Using the JBoss CLI tool, a system property can be added by using the following command:

/system-property=<name>:add(value=<value>)

Property values specified within the JBoss configuration file have a higher precedence than both those specified within a properties file or through a command line argument. System properties are loaded by the JBoss server in the following order:

  1. Defined within the JBoss Configuration
  2. Included Properties File
  3. Command line arguments

In this discussion, we have demonstrated several methods of specifying and utilizing configuration parameters and their order of precedence within applications deployed on JBoss EAP 6.1. After factoring in the application and environmental considerations, you can choose to implement an appropriate solution.


One Comment on “Java/JBoss EAP 6.1+ – Power to the Properties”

  1. 1 christophe said at 10:15 am on November 3rd, 2014:

    Thanks for that nice article.
    I tried your example with AS7.1, but did not work. It seems that deployment overlay works as from AS7.2(EAP6.1)


Leave a Reply