Java/JBoss EAP 6.1+ – Power to the Properties

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

Externalizing your Properties Files

Properties files can also be extracted from the application itself and loaded from an external source. This is useful as it allows for configuration values to be specified per environment, such as separating values for a development environment from a production environment. There are several methods for including external resources onto the classpath of an application. The first method is to configure a deployment overlay.

Deployment Overlay Diagram

Introduced in EAP 6.1, a deployment overlay allows the developer to override the contents of a deployment, such as a library or resource, without having to modify the deployment archive itself within the JBoss server. There are two steps required to implement a deployment overlay:

  1. Specify the contents within the deployment that will be overridden and the location of content that will be used as the replacement
  2. Link the overlay to the deployment(s)

In our case, we want to overlay the properties file that is part of our application with the contents of another. An example properties file called overlay-jboss-properties.properties has been included in the support folder of the project. You will notice there are several files and folders contained within the support folder. We will utilize these throughout the next several sections. Deployment overlays are added to the JBoss server using the JBoss Management Command Line Interface (CLI). The JBoss CLI is called jboss-cli.bat/jboss-cli.sh and found in the <JBOSS_HOME>/bin folder. The JBoss server does not need to be running for deployment overlays to be created. Start the JBoss CLI tool and execute the following commands:

  1. Create the deployment overlay
    /deployment-overlay=propertiesoverlay:add
  2. Replace the properties file within the deployment with the overlay-jboss-properties.properties file in the support folder
    /deployment-overlay=propertiesoverlay/content=WEB-INF\/classes\/jboss-properties.properties:add(content={url=file://<APP_ROOT>/support/deployment-overlay-jboss-properties.properties})
  3. Link the overlay to the deployment archive
    /deployment-overlay=propertiesoverlay/deployment=jboss-properties.war:add

The application does not need to be deployed to run the commands above. JBoss uses the name of the deployment rather than linking a specific deployed artifact. If the application is already deployed, it will need to be redeployed for the overlay to take effect. The application can be redeployed with the following command with the server started and the CLI connected to the instance:

/deployment=jboss-properties.war:redeploy

Reloading the sample application should reflect the property values from the deployment overlay instead of the initial values from the properties file packaged within the application.


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