Your plug-in project can have two types of dependencies. One is to depend on another project. The other is to depend on a .jar file or library.
There are a few things to remember when depending on a library jar file. The first is that these .jar files must be in your plug-in's directory structure, so that they can be included in the OSGi bundle of your plugin, and then accessed by your classes. They must then be added to your classpath, and designated as jars to search through.
This is all done very quickly and easily. So to begin, we first make a new plugin and name it Example3Dependencies. We then put our .jar file into the top level directory of our plugin. (Just copy it in or paste it in.)
The next step is to add the jar to our runtime tab in our manifest editor. So we open the editor, click to the runtime tab and look at the classpath box. Here, we click "add", and select the jars we want to include. Then we save the editor. | ![]() |
If we add the following code to the plugin class file, we'll notice it didn't work.
public void neverCalled() { JavaDocBuilder builder = new JavaDocBuilder(); }
Our classpath was NOT updated. It added the jar to the manifest file, or the plugin.xml, but it did not update the classpath. To do that, right click on your project and select PDE Tools>Update Classpath. This usually fixes most problems regarding packaging jars with your plugin.
And in this case, it did just that. (If your error didn't go away right away, try focussing on the editor of your plugin and pressing ctrl+shift+o, which organizes your import statements and should import this item. Then save the file) We won't run this application, as it doesn't actually do anything. This exercise was just demonstrative.
Most .ui plug-ins depend on a corresponding .core plugin. How do we fascilitate this?
First, make a new plug-in project, and call it Example3Z.
Next, let's try to get a reference to that plug-in's singleton object in a new method. Put the following method in the example3Dependencies.Example3Dependencies.java .java file, right after our neverCalled() method.
public void neverCalled2() { Example3ZPlugin plugin = Example3ZPlugin.getDefault(); }
Next, we have to add it to our dependencies, in the manifest gui editor for the Example3Dependencies project, on the Dependencies tab. Click add and select Example3Z. Then save the file.
If we go back and look at our plugin .java file, example3Dependencies.Example3Dependencies.java, we'll see a new error.
What we must do now to complete the dependency is have Example3Z open up its packages for extending or referencing plug-ins to have access. To do this, open up the Example3Z's manifest gui editor, select the runtime tab, and click Add... next to the Exported Packages list. Finally, select the example3Z package and save the file.