Include external configuration

Documents for the development of and with JVx.

Include external configuration

Postby Development@SIB » Mon Apr 25, 2016 3:01 pm

Every application has its own application zone with one configuration file. The name of the file is config.xml. This file should contain the whole configuration for your application.

But sometimes your configuration has external dependencies or you have a different configuration for your test and production system. In that case, it's better to use an external configuration which contains all system dependent properties. Such an external configuration will reduce your deploment/build effort because your config.xml can be the same for every system/server.

How to use an external configuration?

The config.xml can't be moved to an external location but it's possible to include external properties, e.g.:

Syntax: [ Download ] [ Hide ]
<?xml version="1.0" encoding="UTF-8"?>

<application>
  <include>/home/tom/configuration.properties</include>
  <securitymanager>
    <accesscontroller>com.sibvisions.security.MyAccessController</accesscontroller>
  </securitymanager>
  <property name="password.rule" value="${pwdrule}"/>
</application>

The configuration.properties file:

Syntax: [ Download ] [ Hide ]
securitymanager.class = com.sibvisions.security.MySecurityManager
pwdrule = strict

The result, if you create a config.xml without external properties:

Syntax: [ Download ] [ Hide ]
<?xml version="1.0" encoding="UTF-8"?>

<application>
  <securitymanager>
    <accesscontroller>com.sibvisions.security.MyAccessController</accesscontroller>
    <class>com.sibvisions.security.MySecurityManager</class>
  </securitymanager>
  <property name="password.rule" value="strict"/>
  <pwdrule>strict</pwdrule>
</application>

As you can see in above example, it's possible to use placeholders for values. The placeholders will be replaced automatically with values, but only if you use an external properties file. If you don't use the include tag, the placeholder replacement won't work!

It's also possible to use system and environment parameters as values, with following prefixes:

Syntax: [ Download ] [ Hide ]
${sys:databasePassword}

This will use the value of the system property databasePassword.

Syntax: [ Download ] [ Hide ]
${env:databaseName}

This will use the value of the environment property databaseName.

If you don't use a custom prefix, e.g.

Syntax: [ Download ] [ Hide ]
${databaseName}

the value search order will be:

  1. imported property
  2. system property
  3. environment property

It's also possible to use only imported properties, with following prefix:
Syntax: [ Download ] [ Hide ]
${imp:databaseName}
(an imported property is a value, which was found in an external properties file)

The value replacement syntax also supports partial values, e.g.

Syntax: [ Download ] [ Hide ]
http://${url}:${port}/${context}/web/ui/


Attention

Be careful, if you try to modify/save an application configuration which contains include tags, it won't work because of external references. It will be possible if you modify the file directly via XmlWorker but not via Zone or UpToDateConfigFile. In that case, an Exception with following message will be thrown:

Couldn't save configuration file! The content was modified by <include> declarations.
User avatar
Development@SIB
 
Posts: 310
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation