FAQ How do I make my plug-in connect to other plug-ins?
Like members of a community, plug-ins do not generally live in isolation. Most plug-ins make use of services provided by other plug-ins, and many, in turn, offer services that other plug-ins can consume. Some groups of plug-ins are tightly related, such as the group of plug-ins providing Java development toolsthe JDT plug-insand other plug-ins, such as SWT, stand alone without any awareness of the plug-ins around them. Plug-ins can also expose a means for other plug-ins to customize the functionality they offer, just as a handheld drill has an opening that allows you to insert other attachments such as screwdrivers and sanders. When designing a plug-in, you need to think about what specific plug-ins or services it will need, what it will expose to others, and in what ways it wants to allow itself to be customized by others.
To rephrase all this in Eclipse terminology, plug-ins define their interactions with other plug-ins in a number of ways. First, a plug-in can specify what other plug-ins it requires, those that it absolutely cannot live without. A UI plug-in will probably require the SWT plug-in, and a Java development tool will usually require one or more of the JDT plug-ins. Plug-in requirements are specified in the plug-in manifest file (plugin.xml). The following example shows a plug-in that requires only the JFace and SWT plug-ins:
<requires> <import plugin="org.eclipse.jface"/> <import plugin="org.eclipse.swt"/> </requires>
Your plug-in can reference only the classes and interfaces of plug-ins it requires. Attempts to reference classes in other plug-ins will fail.
Conversely, a plug-in can choose which classes and interfaces it wants to expose to other plug-ins. Your plug-in manifest must declare what libraries (JARs) it provides and, optionally, what classes it wants other plug-ins to be able to reference. This example declares a single JAR file and exposes classes only in packages starting with the prefix com.xyz.*:
<runtime> <library name="sample.jar"> <export name="com.xyz.*"/> </library> </runtime>
Finally, a plug-in manifest can specify ways that it can be customized (extension points) and ways that it customizes the behavior of other plug-ins (extensions).
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.