...
The common delegation mechanism for classloaders is to delegate to the parent first when loading a class. Thus, all classes defined in the container classloader are shared. But when a class reference another class (using an import statement in the java code for example), the referenced classes will be loaded by the same classloader. To avoid such problems, you can use a self-first delegation: classes will be loaded from the classloader, and if not found, it will ask its parent.
SU Classloaders
XBean based service unit can define their own classloader. This can be done by adding the following tag in the main xbean configuration file for the SU (xbean.xml
or servicemix.xml
for the servicemix-lwcontainer
component):
Code Block | ||
---|---|---|
| ||
<classpath [inverse="true"]>
[<nonOverrideable>xxx</nonOverridable>]*
[<hidden>xxx</hidden>]*
[<location>xxx</location>]*
</classpath>
|
The inverse
attribute can be set to true
to use self-first delegation mode.
The nonOverridable
tag can be used to specify that classes with a name starting by the specified string can not be overriden by this classloader (the classloader will always use the parent classes).
The hidden
tag is used to hide specific classes (whose name start with the specified string) defined by the parent classloader.
The location
tag can be used to add jars or directories relative to the SU root to the classloader.
Starting from ServiceMix 3.1, if no classpath is defined, or if no locations are specified, the default ones will be automatically added in the SU classloader:
/
lib/*.jar
lib/*.zip
For ServiceMix 3.0.x versions, you need to define the classpath manually, as the default does not include any locations.