Background:
I have a small problem with Eclipse. I’m working on a workbench plugin which has some classes that validate incoming XML data against a schema. The schema lives inside the plugin project in a ‘./schemas’ folder.
Questions:
- When I run the application, how can I read the schema without using a hardcoded path?
- When the application is deployed the schema will need to live inside a plugin .jar. Will the solution from (1) be any different in this case?
You can use the FileLocator class from org.eclipse.core.runtime to get a URL to a resource in your bundle.
For example, something like
You can get your Bundle object from the BundleContext passed into your Activator (if you have one). Or you could use Platform.getBundle.
You should not assume the url is a file on disk, for exactly the case when the plugin is a jar. You can use URL.openStream to get the contents, or FileLocator.toFileURL() to get a file on disk.