Platform URLs in Eclipse
Frequently people wonder how to "locate" files in Eclipse. In 80% of the cases, the
conversation is about things like
. Sometimes it digresses
to files available inside bundles and, rarely, it involves the "state location" of a bundle
javadoc for more details). Obviously you can use
to work with files in these places. There is another way, though: platform URI.
There are a few ways to work with the "platform" scheme:
||It is used to identify a resource located in the workspace. The next path
segment after "resource" should be the name of a project, which can be
followed by the folder and/or file we want to locate.
is used to locate a resource available in a plug-in/bundle. One really cool thing about this one is that it doesn't really
matter if this resource is available in a directory or in a jar file.
It also doesn't matter if the bundle is installed in a link folder or in the default directory.
The path segment after "plugin" should be the identifier of the bundle,
which can be followed by the path of the resource in the bundle.
one is quite similar to "platform:/plugin", being used to locate
fragment resources instead of bundle resources. As you are probably
guessing, the segment after "fragment" should be the fragment's
use this to access a bundle's stage location. The path segment after
"meta" should be the bundle's identifier, followed by the path of the
resource we want to refer to.
||The "config" segment causes the
platform URI to refer to the configuration area of the running Eclipse (usually the eclipse/configuration directory). This can
be useful to read the config.ini file, for example.
refers to the directory of the Eclipse being executed.
It is interesting to note that, for example,
don't necessarily refer to the same resource. The former is a "pointer" to a plugin.xml file located in a directory
plugins/org.eclipse.mybundle under the directory that Eclipse is installed. The latter points to the plugin.xml of the
"org.eclipse.mybundle" bundle regardless of where it is installed and whether it is jarred or not.
So what can we do with platform URIs? For one, read the contents of the
resources pointed by them. We may also be able to write to such
resources or even delete or create them.
URIs can be a good fit for APIs that would normally use "plain" paths. Take as
an example the
attribute of the extension point below. Because its value is handled as
a URI, we are allowed to refer to an image located in a different