Example: Sharing Java classes between solutions

When you need to use the same Java™ classes in multiple solutions, store those Java classes in a shared library. You can access the Java classes in the shared library by using JavaCompute nodes in your applications.

About this task

If you update those Java classes and redeploy the shared library, those changes are automatically available to all applications that reference that shared library. You do not need to redeploy the referencing applications.

Java classes that are deployed in a shared library are not available to the integration server-wide class loader. When you deploy a shared library that contains Java files, a new class loader is created for that shared library. This class loader contains all Java classes in the shared library, as well as the Java classes from all referenced shared libraries. Java classes in shared library class loaders are isolated from Java classes in the integration server-wide class loader.

A Java class can exist in multiple class loaders if that Java class is contained in a shared library that is referenced by other shared libraries. When you update that Java class by redeploying the shared library that contains it, all class loaders for all shared libraries that contain that Java class are deleted and re-created.

If you include a JavaCompute node in a subflow in a shared library, that node can access the Java classes in that shared library and any referenced shared libraries. If you include a JavaCompute node in a flow or subflow in an application, that node can access the Java classes in a shared library and any shared libraries that are referenced by that shared library. In this case, you must specify a shared library qualifier in the form {shlib1} as the Java configurable service. Java classes in applications, static libraries, or independent projects cannot access Java classes in shared libraries.

The order in which you create your resources is flexible. The following steps describe one way to share Java classes between multiple applications.

Procedure

  1. In the IBM® Integration Toolkit, create a shared library.
  2. If you have existing Java classes, add them to the shared library. Otherwise, you can create your Java classes when you add a JavaCompute node to a message flow.
  3. Create one or more applications to contain the message flows and other resources for your solutions.
  4. Ensure that your applications refer to the shared library that contains the Java classes.
  5. Create one or more message flows in your applications that contain JavaCompute nodes.
  6. Configure each JavaCompute node to point to the Java classes in the shared library.
    Double-click the JavaCompute node and set the Source folder field to the shared library that contains the Java classes.
  7. If you have existing Java classes, click Finish.
  8. If you have not yet created your Java classes, click Next and select a template for your class. Define the Java build settings, then click Finish.

Results

The Java class file opens in the editor. If you view the basic properties for the JavaCompute node, the Java class field is populated with the location of the specified Java class. The Java classloader service field contains a qualifier for the shared library that contains the Java class in the form {sharedLibraryName}.

What to do next

After you create all the resources that your solution requires, deploy the shared library and the referencing applications.

You can deploy your resources by dragging the shared library and the applications onto the integration server. If you use this method, you must deploy the shared library before the applications that reference it. Alternatively, you can add the applications and shared library to a BAR file, then deploy that BAR file.