4.4.2.7. External libraries

Writing code instructions is all about abstraction: no specifics should be included to make that one piece of code instructions suitable for multiple entities. Since you’ve decided to go down this road anyway, then why not take it one step further by reusing your code instructions between projects? You can create an external library of code instructions and use that for multiple projects. Consequently refactoring and introducing new functionality in all projects only requires a single change in code instructions. After that, just generate all project files again and you’ll be fully up to date.

Configure an external library

An externalLibrary should always have a unique name by which attributes can be determined. The path tag contains the absolute path to a folder. The patternsFolder tag contains the relative path to the patterns, the snippetsFolder tag contains the relative path to the snippets.

A external library is defined in the pattern file with the following syntax:

Listing 4.33 <external libraries/> definition syntax
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<pattern xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.firstbase.nl/xsd/personaliom/pattern"
         xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/pattern
                             http://www.firstbase.nl/xsd/personaliom/pattern.xsd">

        ...
        <externalLibraries>
                <externalLibrary name="lib1">
                        <path>absolute path to some folder</path>
                        <patternsFolder>relative path to folder with pattern</patternsFolder>
                        <snippetsFolder>relative path to folder with snippets (velocity files)</snippetsFolder>
                </externalLibrary>
        </externalLibraries>

        ...
</pattern>

And here is an example of using 2 external libraries:

Listing 4.34 <external libraries/> example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<externalLibraries>
        <externalLibrary name="weblib">
                <path>C:\metafactory-libs\myweblib</path>
                <patternsFolder>webpatterns</patternsFolder>
                <snippetsFolder>websnippets</snippetsFolder>
        </externalLibrary>
        <externalLibrary name="rcplib">
                <path>C:\metafactory-libs\myrcplib</path>
                <patternsFolder>rcppatterns</patternsFolder>
                <snippetsFolder>rcpsnippets</snippetsFolder>
        </externalLibrary>
</externalLibraries>

We recommend to use a version control system to contain only the library and nothing else, so that you can safely use it with multiple projects.