A template file is a text file with two main sections, a header and a body.
An example of a RapidJ template can be found here.
Following is a formal definition of the format of a template:
<template> ::= <template header> <template body>
<template header> ::= <start header> [ { NEWLINE <header> }... ] NEWLINE <end header>
<start header> ::= <#-- START TEMPLATE HEADER -->
<end header> ::= <#-- END TEMPLATE HEADER -->
<header> ::= <#-- <parameter>=<value> -->
<template body> ::= a FreeMarker template
<parameter> ::= one of the header parameters
<value> ::= a value for the parameter
The following table describes the available header parameters:
Parameter | Description | Required | Example value |
---|---|---|---|
category | This is a list of sub categories separated by a / character that describes how the template should be categorised. Templates having a category of "generic" are classed as generic templates. | Yes | databases/hsqldb/1.7 |
type | This specifies the type for the template. | Yes | entity |
condition | This allows a template to specify under what conditions a file should be produced. If it is not present then a file (or files) will always be produced according to its type. The condition itself is a template and has access to the same data model that the template body has access to. A file will only be generated if the evaluation of the condition produces "true". | No | ${f.cla(entity.name)}?starts_with("A") |
version | This indicates what version of the template this is. | No | 1.0 |
fileNameTemplate | This allows a template to specify the name of the files that it produces. It itself is a template and has access to the same data model that the template body has access to. | Yes | ${f.cla(entity.name)}TO.java |
relativeOutputDirectory | This specifies the directory that files produced by the template will be written out to, relative to the project directory. Note: relativePackage is also used to determine the final output directory. | Yes | src |
relativePackage | This specifies the package name of files produced by the template, relative to the base package specified for the project. When it is specified, files produced by the template are written out to a location that is calculated from the relativeOutputDirectory, the base package for the project, and the relative package for the template. | No | data.to |
The template body contains the actual template content in the form of a FreeMarker template.
More information about FreeMarker and the template syntax that it uses can be found on its website at .
The template body must contain the checksum tag {{$RapidJ$}}
.
This is used as a place holder for embedding checksums into
generated files.
Customising a template
Disabling/enabling templates
Creating new templates