Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

FAQ 103: How do I find out the install location of a plug-in?

You should generally avoid making assumptions about the location of a plug-in at runtime. To find resources, such as images, that are stored in your plug-in’s install directory, you can use URLs provided by the Platform class. These URLs use a special Eclipse Platform protocol, but if you are using them only to read files, it does not matter.

The following snippet opens an input stream on a file called sample.gif located in a subdirectory, called icons, of a plug-in’s install directory:

Bundle bundle = Platform.getBundle(yourPluginId);
Path path = new Path("icons/sample.gif");
URL fileURL = Platform.find(bundle, path);
InputStream in = fileURL.openStream();

If you need to know the file system location of a plug-in, you need to use Platform.resolve(URL). This method converts a platform URL to a standard URL protocol, such as HyperText Transfer Protocol (HTTP), or file. Note that the Eclipse Platform does not specify that plug-ins must exist in the local file system, so you cannot rely on this method’s returning a file system URL under all circumstances in the future.


FAQ 102 Where do plug-ins store their state?

  • + Share This
  • 🔖 Save To Your Account