Use Ref tags in configuration files
We can define a common configuration element, then reuse that definition by referring to it (using a Ref tag) from elsewhere in the configuration. Ref tags can be used in the same configuration file containing the element definition, or in an included configuration file.
Different approaches are used to specify relationships between the required configuration elements. For example, the following data source definitions are all valid. The first uses no Ref tags, the second uses a combination of direct element definition and Ref tags, and the third uses Ref tags only.
Examples
Use no Ref tags
<dataSource id="blogDS" jndiName="jdbc/blogDS">
<properties
createDatabase="create"
databaseName="/liberty/basics/derby/data/blogDB"/>
<jdbcDriver>
<library>
<fileset dir="/liberty/basics/derby" includes="derby.jar"/>
</library>
</jdbcDriver>
<connectionManager maxPoolSize="10"/>
</dataSource>
Combine direct element definition and Ref tags
<dataSource
id="blogDS"
jndiName="jdbc/blogDS"
connectionManagerRef="derbyPool">
<properties
createDatabase="create"
databaseName="/liberty/basics/derby/data/blogDB"/>
<jdbcDriver libaryRef="derbyLib"/>
</dataSource>
<connectionManager id="derbyPool" maxPoolSize="10"/>
<library id="derbyLib"/>
<fileset dir="/liberty/basics/derby" includes="derby.jar"/>
</library>
Use Ref tags only
Except for the properties element, which is only permitted as nested.
<dataSource
id="blogDS" jndiName="jdbc/blogDS"
connectionManagerRef="derbyPool"
jdbcDriverRef="derbyEmbedded">
<properties
createDatabase="create"
databaseName="/liberty/basics/derby/data/blogDB"/>
</dataSource>
<connectionManager id="derbyPool" maxPoolSize="10"/>
<jdbcDriver id="derbyEmbedded" libraryRef="derbyLib"/>
<library id="derbyLib" filesetRef="derbyFileset"/>
<fileset id="derbyFileset" dir="/liberty/basics/derby" includes="derby.jar"/>
Parent topic: Use include elements, variables, and Ref tags in configuration files