|
Re: Eclipse Plugin - Read from file [message #334682 is a reply to message #334679] |
Tue, 24 February 2009 15:46 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Hi,
You need to use an inputstream. You can't get to the file itself in an
efficient way. It may be inside a jar because plugins can be a jar too.
To access the Inputstream:
Bundle bundleForPlugin = ...get the bundle for the plugin of interest...
InputStream is = null;
try {
is = FileLocator.openStream(bundleForPlugin, new
Path("velocity.properties"), false);
... load from the input stream ...
} catch (IOException e) {
...either not found, or some error reading...
} finally {
if (is != null)
try {
is.close();
} catch(IOException e) {
}
}
Alex wrote:
> Hello,
> I have the following Problem in my Eclipse Plugin:
> In my root-plugin-folder are the two files velocity.properties and
> Templates/TableTemplate.tpl
>
> Now I want velocity to init the velocity.properties file like this:
> velocity.init("velocity.properties");
>
> Problem is, that I get a FileNotFoundException although the file is in
> the plugin root path.
>
> It would be nice if someone will help me to solve this problem.
>
> Thanks...
> Alex
>
--
Thanks,
Rich Kulp
|
|
|
|
Re: Eclipse Plugin - Read from file [message #334684 is a reply to message #334683] |
Tue, 24 February 2009 16:14 |
Eclipse User |
|
|
|
Originally posted by: mickael.istria.openwide.fr
Hello Alex,
you can probably try this
// locate the resource in your plugin
URL resourceUrl =
Platform.getBundle("com.example.plugin").getResource("velocity.properties ");
// return a file path from this url (extract file if necessary
String filePath = FileLocator.toFileURL(resourceURL).getFile();
// use it
velocity.init(filePath);
Hope that helps
Mickael
Alex a écrit :
> Hello,
> first of all: thanks for your help!!
>
> The Problem is, that the Method velocity.init("STRING") is not
> applicable for the argument InputStream. So what I need is to get the
> file-path to the velocity.properties file...
>
> Thanks for help
> Alex
>
|
|
|
Re: Eclipse Plugin - Read from file [message #334686 is a reply to message #334684] |
Tue, 24 February 2009 19:04 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Hi,
The only problem with this is if the file is inside a plugin jar (i.e.
the plugin has not been expanded, which is now the preferred way to
package plugins) then this will cause a copy of the file to be moved
into your .metadata location.
Is velocity a class you can't change? If you can, it would be better to
change it to use an InputStream.
Rich
Mickael Istria wrote:
> Hello Alex,
>
> you can probably try this
>
> // locate the resource in your plugin
> URL resourceUrl =
> Platform.getBundle("com.example.plugin").getResource("velocity.properties ");
>
> // return a file path from this url (extract file if necessary
> String filePath = FileLocator.toFileURL(resourceURL).getFile();
> // use it
> velocity.init(filePath);
>
> Hope that helps
>
> Mickael
>
>
>
> Alex a écrit :
>> Hello,
>> first of all: thanks for your help!!
>>
>> The Problem is, that the Method velocity.init("STRING") is not
>> applicable for the argument InputStream. So what I need is to get the
>> file-path to the velocity.properties file...
>>
>> Thanks for help
>> Alex
>>
--
Thanks,
Rich Kulp
|
|
|
Re: Eclipse Plugin - Read from file [message #334693 is a reply to message #334686] |
Tue, 24 February 2009 22:06 |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
If your talking about the Velocity from Apache, there appears to be an init
method that takes a Properties object. Properties has a load method that
takes an input stream. You can use this to load in the properties from the
InputStream and pass it to the init method.
"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:go1gcm$d43$1@build.eclipse.org...
> Hi,
>
> The only problem with this is if the file is inside a plugin jar (i.e.
> the plugin has not been expanded, which is now the preferred way to
> package plugins) then this will cause a copy of the file to be moved
> into your .metadata location.
>
> Is velocity a class you can't change? If you can, it would be better to
> change it to use an InputStream.
>
> Rich
>
> Mickael Istria wrote:
> > Hello Alex,
> >
> > you can probably try this
> >
> > // locate the resource in your plugin
> > URL resourceUrl =
> >
Platform.getBundle("com.example.plugin").getResource("velocity.properties ");
> >
> > // return a file path from this url (extract file if necessary
> > String filePath = FileLocator.toFileURL(resourceURL).getFile();
> > // use it
> > velocity.init(filePath);
> >
> > Hope that helps
> >
> > Mickael
> >
> >
> >
> > Alex a
|
|
|
|
Re: Eclipse Plugin - Read from file [message #334702 is a reply to message #334696] |
Wed, 25 February 2009 10:55 |
Eclipse User |
|
|
|
Originally posted by: mickael.istria.openwide.fr
Hi,
Inside of Eclipse, you should only use slash-based path (no windows-like
backslashes).
Then try with pTemplatePath = "Templates/TableTemplate.tpl".
I'm not sure it is the actual cause of your issue, but it's worth trying,
Mickael
Alexander Mack a écrit :
> Hello,
> great thanks for your help.
> This solution works still fine for the velocity problem:
>
> URL url =
> Activator.getDefault().getBundle().getResource("velocity.properties ");
> Velocity.init(FileLocator.toFileURL(url).getPath());
>
> But it doesn't work with the templates:
>
> url=Activator.getDefault().getBundle().getResource (pTemplatePath);
> Template lTemplate = Velocity.getTemplate(FileLocator.toFileURL(url).ge
> tPath());
> pTemplatePath is a String like this: "Templates\\TableTemplate.tpl"
>
> The Exception I got is an
> org.apache.velocity.exception.ResourceNotFoundException
>
> I really don't know why the velocity.init(...) can access to the file
> but the velocity.getTemplate method can not.
>
> I would appreciate any help. Thank you!
> Alex
>
|
|
|
|
Re: Eclipse Plugin - Read from file [message #334729 is a reply to message #334704] |
Wed, 25 February 2009 14:58 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Hi,
Look in your actual physical plugin that is installed and verify the
file is physically there. Maybe your build.properties didn't include
that file in the bin exports.
Alexander Mack wrote:
> Hello,
> thanks for your reply, but it didn't work:
> SCHWERWIEGEND: ResourceManager : unable to find resource
> '/D:/TEST/eu.emundo.atomspro.generator/Templates/tableTempla te.tpl' in
> any resource loader.
>
> Which is the same error I got before. I'm really frustrated because with
> "velocity.properties" it works fine.
> If i put the template file into the workspace root and try to make this:
>
> url=Activator.getDefault().getBundle().getResource("tableTemplate ");
> Template lTemplate = Velocity.getTemplate(FileLocator.toFileURL(url).ge
> tPath());
> it will not work too!
>
> Very Crazy I think...
>
--
Thanks,
Rich Kulp
|
|
|
|
Powered by
FUDForum. Page generated in 0.03878 seconds