Working with Properties in Jahia DXP

Jahia is the only DXP that truly empowers you to deliver personalized journeys powered by customer data Learn how here

Properties are a way to configure your application.  Most properties are stored as key/value pairs in a file that can be defined as one monolith property file or broken down into multiple property files.  Using property files have two major advantages:

  • Centralized location to manage all configurations settings
  • Eliminate hard coded configurations in code

With the two above advantages, working with properties is very important especially in large enterprise applications.  In Jahia DX, there are three main ways to work with properties:

  • OSGi Configuration
  • Spring Configuration
  • Site Settings

At this time, we will be covering how to work with OSGi configurations.  But before we begin, we will use two Apache Felix subprojects:

NOTE: iPOJO and Blueprint can be used in replace of SCR to manage configurations.  However, this is outside of this blog and may be revisited later using the above APIs.

OSGi Console

The OSGi console will allow us to upload and set up the SCR OSGi bundle.  In order to get to the console, please go to http://localhost:8080/tools/osgi/console/bundles. This will allow us to install and activate the SCR sub project.


Next we need to prepare our project to include a dependency so that we can use annotations to map listeners and declare services.  Here we are including the SCR annotations dependencies.









Next we set up the build plugin to generate the OSGi descriptor file that will be declare and bind the services in an XML format. It will also create a configuration file that will allow the configuration admin to use to allow mapping to the properties file and set up a form UI for each property.














Configuration Admin

Using configuration admin in OSGi is not just setting up the services on startup, It’s powerful enough to update all services that rely on this properties when it's updated real time.  The configurations are all stored in the digital-data/modules folder that is scanned for bundles or configurations changes.  Using the configuration admin console to change the properties on the fly will only update the properties in the digital-data/modules and not the properties files in your source location.  Therefore, limit the use of real time updates to quick POC since property changes will not get persisted in your source safe.  Also, allow the configuration admin to manage the properties for service since it restart services when it detects property changes.

private void loadConfiguration(final Bundle bundle, final Enumeration<URL> urls) throws IOException {

  if (urls != null) {


          // Loop through the urls.

          while (urls.hasMoreElements()) {


              // Remove the CFG from the file name to use to get the configuration object for the service.

              final Configuration configuration = configurationAdmin

                      .getConfiguration(fileName.replace(CFG_EXTENSTION, ""));

              if (configuration != null) {

                  final Properties properties = new Properties();


                  final Dictionary dictionary = new Hashtable<Object, Object>(properties);








The loadConfiguration method processes the properties files found in your OSGi bundle.  The user defined properties filename is the fully qualified class name that services the class.  The filename, excluding the extension, is the persistent identifier, PID, of the configuration and can be used to get the configuration object of the service.  This allows properties to be injected into the service to get ready for use, which is persisted in the digital-data/modules folder.

A service class can be registered as an OSGi service using the SCR annotations.  Below, this example service has one property that is set on start of this service.  The update method has a @Modified that is executed when configuration has changed.  The update method sets the apiUrl instance variable to be used by the service or can be used by other services or component through the getter method.


      label = "Example Service",

      description = "This is an example service to demo configuration",

      immediate = true,

      metatype = true


@Service(value = ExampleService.class)

public class ExampleServiceImpl implements ExampleService {


      label = "API Url",

      description = "This is the api url key.",



private static final String API_URL_PARAM_NAME = "api.url";

private String apiUrl;

public String getApiUrl() {

  return apiUrl;


public void setApiUrl(final String apiUrl) {

  this.apiUrl = apiUrl;




* @param ctx



protected void start(final ComponentContext ctx) {"Successfully registered ExampleService");





* This method will be executed when the .cfg is updated.


* @param properties



protected void update(final Map<String, Object> properties) {

  this.apiUrl = (String) properties.get(API_URL_PARAM_NAME);"apiUrl is {}", apiUrl);



When the maven goal install is executed, the SCR build plugin generates this service definition file that registers this example service as an OSGi service in the OSGi container.


<?xml version="1.0" encoding="UTF-8"?>

<scr:component xmlns:scr="" immediate="true" name="org.jahia.modules.configuration.example.service.ExampleService" activate="start" deactivate="stop" modified="update">

  <implementation class="org.jahia.modules.configuration.example.service.ExampleService"/>

  <service servicefactory="false">

      <provide interface="org.jahia.modules.configuration.example.service.ExampleService"/>


  <property name="api.url" value="http://localhost:8080"/>

  <property name="" value="org.jahia.modules.configuration.example.service.ExampleService"/>


When using @Property the SCR plugin will create a metatype XML and properties file for the service during build time. These two files are used by the configuration admin present a ui to the user for visibility of the properties.


<?xml version="1.0" encoding="UTF-8"?><metatype:MetaData xmlns:metatype="" localization="OSGI-INF/metatype/org.jahia.modules.configuration.example.service.ExampleService">

  <OCD id="org.jahia.modules.configuration.example.service.ExampleService" name="" description="%org.jahia.modules.configuration.example.service.ExampleService.description">

      <AD id="api.url" type="String" default="http://localhost:8080" name="" description="%org.jahia.modules.configuration.example.service.ExampleService.api.url.description"/>


  <Designate pid="org.jahia.modules.configuration.example.service.ExampleService">

      <Object ocdref="org.jahia.modules.configuration.example.service.ExampleService"/>



org.jahia.modules.configuration.example.service.ExampleService.api.url.description=This is the api url key. Service

org.jahia.modules.configuration.example.service.ExampleService.description=This is an example service to demo configuration Url

This property file below is defined by a developer. The properties values are used to update the service. This configuration update is handled but the loadConfiguration method in the Activator class.



Using the configuration admin really makes managing properties easier in the OSGi container.  This approach can be improved to be environment observant to load environment specific properties for complex deployment pipeline.

Next Release

In Jahia DX 7.2, we will be incorporating a more powerful way to manage configuration using Karaf.  This will result in another blog working with configuration in Karaf and Blueprint.



Sajid Momin