API for reading Eclipse plugin dependencies

The Eclipse platform provides an API to allows that you can access in information of the MANIFEST.MF. For example you could read the dependencies of your plugin.

For this example create a plugin “de.vogella.pde.dependencies”. See Eclipse Plugin development for examples on how to develop plugins. Use the “Hello, World Command” template.

Define dependendies to the following plugins:
– org.eclipse.ui
– org.eclipse.core.runtime

Change the command to the following.

[sourcecode language=”java”]

package de.vogella.pde.dependencies.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;

public class PrintDependencies extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
String requireBundle = (String)Platform.getBundle("de.vogella.pde.dependencies").getHeaders().get(
try {
ManifestElement[] elements = ManifestElement.parseHeader(
Constants.BUNDLE_CLASSPATH, requireBundle);
for (ManifestElement manifestElement : elements) {
System.out.println( manifestElement.getValue());
} catch (BundleException e) {
return null;


If you now run your new plugin it and select your command it will print out the dependencies of your plugin.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse and tagged , , , . Bookmark the permalink.

2 Responses to API for reading Eclipse plugin dependencies

Comments are closed.