Helma uses the concept of a module path to look up and load modules that is similar to the PATH environment variable used to find executables on most operating systems. By default, the module path consists of two entries:
The application root, which is the parent directory of the command line script, or the current working directory if called without script argument.
The system modules root, which corresponds to the modules directory in the Helma NG home directory.
Helma NG provides several ways to access and set the module path. The simplest
is to set the
HELMA_MODULE_PATH environment variable, separating multiple entries
with ':' or whatever character is used to separate PATH entries on your system:
Alternatively, you can define the module path using the helma.modulepath Java system property, and you can add entries to the module path using the addRepository() method in the helma/system module.
Helma NG provides three functions with different semantics to load modules:
The require function provides the functionality defined in the ServerJS Securable Modules proposal. It tries to locate a module in the module path, loads it and returns its exports object.
The import function builds on top of require, additionally setting a property in the calling module scope whose name is the name of the loaded module and whose value is the loaded module's exports object.
The include function builds on top of require, additionally copying all exported properties of the loaded module to the calling module scope.
The export function provides an alternative method to the exports object to define exported properties in a module by passing the names of exported properties as arguments.
This function adds a jar file or directory to the classpath. By default, all jar files in the Helma NG lib directory are included in the classpath.