Reputation: 14697
I am loading a property file in the eclipse bundle but my code is using InternalPlatform
from eclipse package which is not the best way to do that because it is restricted package from the eclipse . How do I load this file from the classpath.
public Properties getProperties(String resourceName){
Bundle bundle = InternalPlatform.getDefault().getBundle("sample-bundle");
try {
return PropertyFactory.getProperties(new URL("platform:/plugin/" + bundle.getSymbolicName() + "/" + resourceName));
} catch (Exception e) {
logger.error("Unable to load aegis config {}", e.getMessage(), e);
return null;
}
private static Properties getProperties(URL url) throws IOException {
Properties properties = new Properties();
logger.info("Loading Properties from {}", url);
properties.load(url.openStream());
return properties;
}
Upvotes: 0
Views: 427
Reputation: 111142
The Platform
class provides an official way to get the bundle for a plugin given its id:
Bundle bundle = Platform.getBundle("sample-bundle");
You can then use the FileLocator
class to find a resource in the bundle:
IPath path = new Path("relative path of resource in bundle");
URL url = FileLocator.find(bundle, path, null);
Note: Platform
is org.eclipse.core.runtime.Platform
in the org.eclipse.core.runtime
plugin. Path
is org.eclipse.core.runtime.Path
.
Upvotes: 1