Helma Logo
main list history

Version 2 by hannes on 05. October 2009, 16:35

25is to set the HELMA_MODULE_PATH `HELMA_MODULE_PATH` environment variable, separating multiple entries

Version 1 by hannes on 28. September 2009, 16:48

1### Module Path Setup
3Helma NG loads JavaScript resources using a module loader that is compliant with
4the ServerJS Securable Modules proposal:
5
6  <https://wiki.mozilla.org/ServerJS/Modules/SecurableModules>
7
8Helma NG actually goes one step further and makes sure every module has its own
9top level scope, so modules are fully isolated from each other, providing a
10programming environment that resembles that of Python environment more than
11the one of ordinary client-side JavaScript runtime.
12
13Helma uses the concept of a module path to look up and load modules that is
14similar to the PATH environment variable used to find executables on most
15operating systems. By default, the module path consists of two entries:
16
17  1. The application root, which is the parent directory of the command line
18    script, or the current working directory if called without script
19    argument.
20
21  2. The system modules root, which corresponds to the modules directory in
22    the Helma NG home directory.
23
24Helma NG provides several ways to access and set the module path. The simplest
25is to set the HELMA_MODULE_PATH environment variable, separating multiple entries
26with ':' or whatever character is used to separate PATH entries on your system:
27
28    export HELMA_MODULE_PATH=../foo/lib:../my/lib
29
30Alternatively, you can define the module path using the helma.modulepath Java
31system property, and you can add entries to the module path using the
32addRepository() method in the helma/system module.
33
34### Module and Resource Loading
35
36Helma NG provides three functions with different semantics to load modules:
37
38`require(moduleName)`
39
40> The require function provides the functionality defined in the ServerJS
41> Securable Modules proposal. It tries to locate a module in the module path,
42> loads it and returns its exports object.
43
44`import(moduleName)`
45
46> The import function builds on top of require, additionally setting a
47> property in the calling module scope whose name is the name of the
48> loaded module and whose value is the loaded module's exports object.
49
50`include(moduleName)`
51
52> The include function builds on top of require, additionally copying
53> all exported properties of the loaded module to the calling module scope.
54
55`export(propertyName[, ...])`
56
57> The export function provides an alternative method to the exports object
58> to define exported properties in a module by passing the names of exported
59> properties as arguments.
60
61`addToClasspath(pathName)`
62
63> This function adds a jar file or directory to the classpath. By default,
64> all jar files in the Helma NG lib directory are included in the classpath.
65
66`getResource(pathName)`
67
68> This looks for a file with the given path name in the module path and
69> returns a resource object. This can be used to load resources other than
70> JavaScript files using the same lookup rules as the module loader.