Using include elements in configuration files

You can keep all your configuration in a single server.xml file, or you can use include elements to consolidate configurations from separate files to create the structure that is most useful to you.

About this task

It can be easier to maintain a complex configuration by splitting it across a set of files. For example:
  • You might want to include a file that contains variables that are specific to the local host, so that your main configuration can be used on multiple hosts.
  • You might want to keep all of the configuration for a particular application in a separate file that can be versioned with the application itself.


This is the syntax for including a configuration file. You can set the optional attribute as true if you want to skip the include file when it cannot be found :
<include optional="true" location="pathname/filename"/>
<include optional="true" location="url"/>
The following list shows the possible locations; they are searched in the order shown.
  1. in a location specified relative to the parent file
  2. in the server configuration directory
  3. in a location specified as an absolute path
  4. on a web server
To ensure that your include configuration behaves predictably, you need to be aware of the following processing rules for included configuration files:
  • For singleton services such as logging, or application monitoring, entries are processed in the order they appear in the file and later entries add to or override previous ones. This is also true for configuration instances, for example an application or data source, where the configuration instances have the same ID.
  • Include statements can be placed anywhere within the <server /> element.
  • Each included file must contain a <server /> element that matches the one in the parent configuration file.
  • Included files can nest other included files.
  • Each included file is logically merged into the main configuration at the position that the <include /> statement occurs in the parent file.

In the following example, the primary server configuration file server.xml includes the contents of the blogDS.xml configuration file, which is located in the shared configuration directory. The blogDS.xml file contains a data source definition. This definition has been put in a separate configuration file so that it can be included in several different server.xml files, and thereby used across multiple server instances.

Here is example code from the server.xml file:
  <application id="blog" location="blog.war" name="blog" type="war"/>
  <include optional="true" location="${shared.config.dir}/blogDS.xml"/>
Here is the example code from the blogDS.xml file:
  <dataSource id="blogDS" jndiName="jdbc/blogDS" jdbcDriverRef="derbyEmbedded">
    <properties createDatabase="create" databaseName="C:/liberty/basics/derby/data/blogDB" />
  <jdbcDriver id="derbyEmbedded"/>
      <fileset dir="C:/liberty/basics/derby" includes="derby.jar" />