Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Eclipse Plugin - Read from file
Eclipse Plugin - Read from file [message #334679] Tue, 24 February 2009 15:18 Go to next message
Alexander Mack is currently offline Alexander MackFriend
Messages: 100
Registered: July 2009
Senior Member
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
Re: Eclipse Plugin - Read from file [message #334682 is a reply to message #334679] Tue, 24 February 2009 15:46 Go to previous messageGo to next message
Eclipse UserFriend
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 #334683 is a reply to message #334682] Tue, 24 February 2009 15:56 Go to previous messageGo to next message
Alexander Mack is currently offline Alexander MackFriend
Messages: 100
Registered: July 2009
Senior Member
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 #334684 is a reply to message #334683] Tue, 24 February 2009 16:14 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #334696 is a reply to message #334693] Wed, 25 February 2009 10:04 Go to previous messageGo to next message
Alexander Mack is currently offline Alexander MackFriend
Messages: 100
Registered: July 2009
Senior Member
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 #334702 is a reply to message #334696] Wed, 25 February 2009 10:55 Go to previous messageGo to next message
Eclipse UserFriend
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 #334704 is a reply to message #334702] Wed, 25 February 2009 11:20 Go to previous messageGo to next message
Alexander Mack is currently offline Alexander MackFriend
Messages: 100
Registered: July 2009
Senior Member
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...
Re: Eclipse Plugin - Read from file [message #334729 is a reply to message #334704] Wed, 25 February 2009 14:58 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Eclipse Plugin - Read from file [message #334732 is a reply to message #334704] Wed, 25 February 2009 15:11 Go to previous message
Alexander Mack is currently offline Alexander MackFriend
Messages: 100
Registered: July 2009
Senior Member
Hello again,
could it be that this is a velocity problem? Because if I put the file for
example in the folder D:\\Templates\\tableTemplate.tpl and try this:

File file = new File("D:\\Templates\\tableTemplate.tpl");
System.out.println(file.exists());
Template lTemplate = Velocity.getTemplate(file.getAbsolutePath());

File.exists() says true but the Velocity.getTemplate() method throws again
a ResourceNotFoundException:
SCHWERWIEGEND: ResourceManager : unable to find resource 'D:\\.....

Perhaps I added velocity to my plugin project in the wrong way:
I just added in the plugin.xml -> Runtime the two jars velocity-1.5.jar
and velocity-dep-1.5.jar to the classpath.

I hope that you can help me...

Best regards

Alex
Previous Topic:Eclipse cairo issue
Next Topic:WizardDialog default button
Goto Forum:
  


Current Time: Tue May 07 13:38:38 GMT 2024

Powered by FUDForum. Page generated in 0.03878 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top