FAQ How can I share a JAR among various plug-ins?
Suppose that plug-in A and plug-in B both use xmlparser.jar. In your workspace are two projects (for A and B), each containing a copy of the xmlparser.jar library. This is clearly not ideal: Two copies of the JAR are loaded at runtime, and classes from those JARs will not be compatible with each other, as they are loaded by different class loaders. (You will get a ClassCastException if you try to cast a type from one library into a type from the other library.)
Declaring xmlparser.jar as an external JAR does not work, as there is no easy way during deployment of your plug-ins to manipulate your plug-ins classpath so that they can see the library. The best way to share libraries is to create a new plug-in that wraps the library you want to share.
Declare a new plug-in, C, to contain the library JAR, and make both plug-in A and plug-in B dependent on plug-in C. Make sure that plug-in C exports its library so other plug-ins can see it:
<runtime> <library name="xmlParserAPIs.jar"> <export name="*"/> </library> </runtime>
When you deploy these three plug-ins, they will all share the same library. Note that in some situations, sharing libraries between plug-ins is not possible. If two plug-ins require different or incompatible versions of the same library, they have no choice but to each have a copy of the library.
This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.