import

Syntax

[#import packageName.simpleName]
or
[#import packageName.*]

where:

Description

The import directive makes the referenced element (text template, ruleset or Java type) directly available in the template. You can then use the element using its simple name, rather than having to use a qualified name. You may also make the whole content of a package directly available using the '*' (star) character.

When an element is referenced in the template contents using a simple name (e.g. MyElement), the element is resolved this way:

  1. The element is searched in the template declared package.
  2. If not found, it is searched in the named imports (e.g. import com.mycompany.example.MyElement)
  3. If not found, it is searched in the package imports (e.g. import com.mycompany.example.*)

Examples

A script that won't compile due to an unresolved type:

[#script myScript(values : List)] [#-- List is unresolved ! --]
[#/script]

The script can be rewritten to use a qualified name:

[#script myScript(values : java.util.List)] [#-- java.util.List is valid --]
[#/script]

Or we can introduce an import to keep the simple notation:

[#import java.util.*]
...
[#script myScript(values : List)] [#-- List is resolved to java.util.List --]
[#/script]

Importing a text template:

[#import com.mycompany.example.Copyright]
...
[#include Copyright()] [#-- Copyright is resolved to com.mycompany.example.Copyright --]