Cedric Reichenbach
Cedric Reichenbach

Reputation: 9319

Image path inside an eclipse plugin

I'm trying to refer to images inside an eclipse plugin (e.g. for icons) in the following way (from a tutorial on the eclipse FAQ website):

Bundle bundle = Platform.getBundle(PLUGIN_ID);
Path path = new Path("icons/doodledebug-icon.png");
URL fileURL = FileLocator.find(bundle, path, null);
URL resolved = null;
try {
    resolved = FileLocator.resolve(fileURL);
} catch (IOException e) {
    throw new RuntimeException(e);
}
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(resolved);

This works fine when testing, i.e. in the runtime eclipse application. But it leads to errors when creating an update site and using this one. The path seems to be not syntactically correct:

C:\Program Files\eclipse EE indigo\file:\C:\Users\Me\.eclipse\org.eclipse.platform_3.7.0_1202875443\plugins\DoodleDebugServer-Plugin_1.0.0.201208241809.jar!\icons\doodledebug-icon.png

Why is this breaking when executed in a jar, or how should I do this correctly?

Upvotes: 1

Views: 1088

Answers (1)

Peter Roe
Peter Roe

Reputation: 446

Assuming the icons directory is at the root level of the project, I believe you can just add a slash to the front of the path:

Path path = new Path("/icons/doodledebug-icon.png");

Upvotes: 2

Related Questions