Reputation: 6822
I'm trying to use Properties's load()
method in my Eclipse plugin project. Since I wanna put the propertie file in a folder like this:
Pluging Project/
|
+----/src/...
+----/config/config.properties
+----/icons/...
+----META-IN/
+----build.properties
+----plugin.xml
And then I try code like this but failed:
Properties prop = new Properties();
InputStream inputStream = (InputStream) Activator.getDefault().getBundle().getEntry("/config/config.properties").getContent();
prop.load(inputStream);
This method receipt a input byte stream as parameter. And I'm pretty sure Activator.getDefault().getBundle().getEntry()
returns a InputStream.
And if I put the propertie file in the same location of the calling class and use
InputStream inputStream = this.getClass().getResourceAsStream("config.properties");
It will go well.
So any hints?
Upvotes: 1
Views: 145
Reputation: 111142
The URL
returned by Bundle.getEntry
uses an internal Eclipse scheme and doesn't always support getContents()
. You need to call org.eclipse.core.runtime.FileLocator.toFileURL()
to convert it:
URL url = Activator.getDefault().getBundle().getEntry("/config/config.properties");
url = FileLocator.toFileURL(url);
InputStream inputStream = (InputStream)url.getContent();
Also make sure you have the config
directory listed in the build.properties
Upvotes: 1