load any resource from any installed plugin of Eclipse

one common solution for this like:

- this.getClass().getResources()

but this way force you have to put your resources into src directory of Eclipse, this won't work under situation: your plugin is a pure library plugin, i.e. it hasn't src directory at all and it's not a java project, which hasn't java nature in its .project file

A better solution I find is:
 Bundle myBundle = Platform.getBundle(MY_BUNDLE_ID);
 URL fileUrl = myBundle.getResource("/" + resourceName);


it support:
- your plugin can use any package style, say, as a jar, as a directory
- your resource can locate in src or just resource directory

你可能感兴趣的:(java,eclipse)