In many ways Ant2 needs to follow rules similar to a number of
different application servers with respect to ClassLoader management.
Ant2 will create a number of different ClassLoaders that have access
to different sets of resources (and thus Classes). The main reason
for this arrangment is to partition different sections of the
application such as the Container, the Task API, task/type libraries
and support libraries.
The recomended structure for ClassLoader relationships is a hierarchy.
When a ClassLoader is asked for a resource (or a class) it first delegates
to it's parent to ask for the resource. If the resource is not present in
its parent ClassLoader then the ClassLoader attempts to locate the resource
in it's own store. In practice this means that all the classes (and static
variables defined by said classes) in a parent ClassLoader are shared with
the child ClassLoaders.
Using kooky ascii art, the specific ClassLoader structure for Ant2 is as
follows:
 |
 |
 |
 |
Bootstrap
|
System
|
Common
/ \
Container Shared
/ \
Antlib1 Antlib2 ...
|
 |
 |
 |
 |