Eclipse RCP/OSGI Classloader HOWTO

I am working on a new desktop application using Eclipse Rich Client Platform (RCP). Eclipse RCP applications are comprised of plugins. The plugins are not any ordinary old plugins. They are Open Standard Gateway Initiative (OSGI) plugins.

One feature of OSGI plugins is classpath separation. One plugin can be running dom4j 1.5 and another dom4j 1.6, and there is no conflict. A nice idea. Unfortunately, a combination of an extraordinarily poor user interface in the Eclipse IDE coupled with a classloader that goes out of its way not to load classes, makes it very difficult for the newly initiated to get going.

While I was away at OSCON2005, a developer on the project spent 8 full work days trying to figure out how to get our plugin to a load classes from a jar. While I was at OSCON I met Scott Delap. Scott is the maintainer of clientjava.com and knows a lot about RCP. Having taken a quick look at the problem myself and finding no documentation on to get the Eclipse IDE to do the right magic I called Scott. He helped through a fairly involved process, and one that is dependent on order and I was then able load jars!

With agreement from Scott, I am making the HOWTO available below. It covers:

  • Loading classes from jars.
  • Exporting classes to make them visible to other plugins.
  • Swapping in another classloader to load resources.

Eclipse 3.1 OSGI classloading HOWTO

Published
Categorized as Java

By Greg Luck

As Terracotta’s CTO, Greg (@gregrluck) is entrusted with understanding market and technology forces and the business drivers that impact Terracotta’s product innovation and customer success. He helps shape company and technology strategy and designs many of the features in Terracotta’s products. Greg came to Terracotta on the acquisition of the popular caching project Ehcache which he founded in 2003. Prior to joining Terracotta, Greg served as Chief Architect at Australian online travel giant Wotif.com. He also served as a lead consultant for ThoughtWorks on accounts in the United States and Australia, was CIO at Virgin Blue, Tempo Services, Stamford Hotels and Resorts and Australian Resorts and spent seven years as a Chartered Accountant in KPMG’s small business and insolvency divisions. He is a regular speaker at conferences and contributor of articles to the technical press.