Use Ref tags in configuration files
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.
Example
Example 1: Use no Ref tags.
<dataSource id="blogDS" jndiName="jdbc/blogDS"> <properties createDatabase="create" databaseName="C:/liberty/basics/derby/data/blogDB"/> <jdbcDriver> <library> <fileset dir="C:/liberty/basics/derby" includes="derby.jar"/> </library> </jdbcDriver> <connectionManager maxPoolSize="10"/> </dataSource>
Example 2: Combine direct element definition and Ref tags.<dataSource id="blogDS" jndiName="jdbc/blogDS" connectionManagerRef="derbyPool"> <properties createDatabase="create" databaseName="C:/liberty/basics/derby/data/blogDB"/> <jdbcDriver libaryRef="derbyLib"/> </dataSource> <connectionManager id="derbyPool" maxPoolSize="10"/> <library id="derbyLib"/> <fileset dir="C:/liberty/basics/derby" includes="derby.jar"/> </library>
Example 3: 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="C:/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="C:/liberty/basics/derby" includes="derby.jar"/>
Parent topic: Use include elements, variables, and Ref tags in configuration files