skip to main content
Gantt > Programmer's documentation > Developing with the JViews Gantt SDK > Using JViews products in Eclipse RCP applications > Providing access to class loaders
 
Providing access to class loaders
Many services in JViews need to look up a resource. Since the classical way to provide access to resources is a class loader, JViews uses class loaders for this purpose. But in Eclipse/RCP applications, each plug-in corresponds to a class loader, and the JViews class loader sees only its own resources, not the application resources. To fix this problem, you can register plug-in class loaders with JViews through the IlvClassLoaderUtil.registerClassLoader function. Each resource lookup then considers the registered class loaders and, if the plug-ins are configured accordingly, also considers the dependencies of the registered class loaders.
The code for doing this is usually located in a plug-in activator class. For example:
public class MyPluginActivator extends AbstractUIPlugin
{
    /**
     * This method is called upon plugin activation
     */
    public void start(BundleContext context) throws Exception {
      super.start(context);
      IlvClassLoaderUtil.registerClassLoader(getClass().getClassLoader());
    }
 
    /**
     * This method is called when the plugin is stopped
     */
    public void stop(BundleContext context) throws Exception {
      super.stop(context);
      IlvClassLoaderUtil.unregisterClassLoader(getClass().getClassLoader());
    }
 
  }
The overriding of stop() is necessary so that, when the plug-in gets unloaded, JViews gets notified about the plug-in that is going to stop and can drop references to its resources or instances of its classes. The activator plug-in is usually also the place where IlvProductUtil.registerApplication is called.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.