Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: distinguish self-first configuration for shared libraries and service units

...

The other benefit of using classloaders is that you can have isolated components. You could deploy two components (or SU) which use different version of the same library without any problems. This is not possible if you put all the dependencies in the container classpath.

Self-first delegation

...

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 references 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 where classes are loaded from the classloader, and if not found, it will ask its parent.

Shared libraries and SMX components

To enable self-first delegation for shared libraries and components change In the service's POM.XML to include

Code Block
langxml
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.servicemix.tooling</groupId>
      <artifactId>jbi-maven-plugin</artifactId>
      <configuration>
        <classLoaderDelegation>self-first</classLoaderDelegation>
      </configuration>
    </plugin>
  </plugins>
</build>

SU Classloaders

XBean based service units 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):

...

The location tag can be used to add jars or directories relative to the SU root to the classloader.

New in ServiceMix 3.1

Starting with 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:

...

For ServiceMix 3.0.x versions, you need to define the classpath manually, as the default does not include any locations.

New in ServiceMix 3.2

You can now reference Shared Libraries and Components classloaders using the following syntax:

...