Access resources within a plugin

Hello,

I have been struggling to access resources within a plugin. I would like to include files (such as images, text files, etc.) that would be accessible to the plugin java code but I am not succeeding. I know it is rather a Java issue, but I hope I can get some help in this forum.

In particular, I have created a /css directory under my plugin directory (at the same level as src, icons, etc.). I have placed a file there. Now, I would like to read it. But the getResourceAsStream("/css/mycss.css") command is not finding it.

Any ideas?

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com

If you want to access ressources with standard Java mechanism, they need to be in the classpath i.e. usually inside the src-folder of your plugin. Or you add your resource folders to the classpath (via MANIFEST.MF).
You may, however, also use Eclipse’s bundle mechanism to load things outside the classpath but inside the plugin. The “magic” class is Bundle, have a look at e.g. the RCorePlugin class of the R-Feature that tries to find an R executable that is shipped with the plugin.

Thorsten

Hello,

I tried (and succeeded) doing the following:

[...] Bundle bundle = Platform.getBundle("com.mycompany.myplugin"); Path path = new Path("css/Pastel.css"); URL fileURL = FileLocator.find( bundle, path, null ); InputStream orig = fileURL.openStream(); [...]

The required imports are:

import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; import org.eclipse.core.runtime.FileLocator;

Thanks for your help!