You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Adam Cornett <ad...@gmail.com> on 2007/05/05 09:10:05 UTC

File Resource Loader

I am implementing Velocity in a website and everything is going
fine...except I can't get it to load templates from inside java code.  For
example, one class e-mails a registration confirmation to a user, I have a
template that sends them a pretty html e-mail, however when I try to load
the template, I get a
org.apache.velocity.exception.ResourceNotFoundException.  I have tried
several different fixes, from putting a copy of the template in every
reasonable directory, setting the file resource loader path... nothing
works.  Here is some of my code:

/* The function is called from a static method in a class via another
template located at /familyweekend/regapp/test_email.vm, with the template
file in the same directory. */
ExtendedProperties ep = new ExtendedProperties();
ep.setProperty("file.resource.loader.path", "/familyweekend/regapp,
/v_templates, .");
ep.setProperty("file.resource.loader.cache ", true);
ep.setProperty("file.resource.loader.modificationCheckInterval", 2);
ep.setProperty("resource.loader", "file");
VelocityEngine ve = new VelocityEngine();
ve.setExtendedProperties(ep);
Template tem== ve.getTemplate(EMail_Template);    /* EMail_Template is a
String defined else where, and yes, its the right name */

And it throws the error everytime at the last line.  I have no idea what I'm
doing wrong, and I've read the online documentation several times and it
doesn't seem to help.
-Adam Cornett

Re: File Resource Loader

Posted by Nathan Bubna <nb...@gmail.com>.
On 5/5/07, Adam Cornett <ad...@gmail.com> wrote:
> I am implementing Velocity in a website and everything is going
> fine...except I can't get it to load templates from inside java code.

are you using one of the servlets we provide (like the VelocityViewServlet)?

> For
> example, one class e-mails a registration confirmation to a user, I have a
> template that sends them a pretty html e-mail, however when I try to load
> the template, I get a
> org.apache.velocity.exception.ResourceNotFoundException.  I have tried
> several different fixes, from putting a copy of the template in every
> reasonable directory, setting the file resource loader path... nothing
> works.  Here is some of my code:
>
> /* The function is called from a static method in a class via another
> template located at /familyweekend/regapp/test_email.vm, with the template
> file in the same directory. */
> ExtendedProperties ep = new ExtendedProperties();
> ep.setProperty("file.resource.loader.path", "/familyweekend/regapp,
> /v_templates, .");
> ep.setProperty("file.resource.loader.cache ", true);
> ep.setProperty("file.resource.loader.modificationCheckInterval", 2);
> ep.setProperty("resource.loader", "file");
> VelocityEngine ve = new VelocityEngine();
> ve.setExtendedProperties(ep);
> Template tem== ve.getTemplate(EMail_Template);    /* EMail_Template is a
> String defined else where, and yes, its the right name */

what properties are you using to configure Velocity elsewhere?  the
properties that work to load the template that calls this static
method should work here too.

> And it throws the error everytime at the last line.  I have no idea what I'm
> doing wrong, and I've read the online documentation several times and it
> doesn't seem to help.

have you tried using the WebappLoader from VelocityTools?  it is more
user-friendly in a webapp setting.

> -Adam Cornett
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: File Resource Loader

Posted by Will Glass-Husain <wg...@gmail.com>.
That looks ok to me.

Could it be a capitalization or file permission issue?

WILL

On 5/5/07, Adam Cornett <ad...@gmail.com> wrote:
>
> I am implementing Velocity in a website and everything is going
> fine...except I can't get it to load templates from inside java code.  For
> example, one class e-mails a registration confirmation to a user, I have a
> template that sends them a pretty html e-mail, however when I try to load
> the template, I get a
> org.apache.velocity.exception.ResourceNotFoundException.  I have tried
> several different fixes, from putting a copy of the template in every
> reasonable directory, setting the file resource loader path... nothing
> works.  Here is some of my code:
>
> /* The function is called from a static method in a class via another
> template located at /familyweekend/regapp/test_email.vm, with the template
> file in the same directory. */
> ExtendedProperties ep = new ExtendedProperties();
> ep.setProperty("file.resource.loader.path", "/familyweekend/regapp,
> /v_templates, .");
> ep.setProperty("file.resource.loader.cache ", true);
> ep.setProperty("file.resource.loader.modificationCheckInterval", 2);
> ep.setProperty("resource.loader", "file");
> VelocityEngine ve = new VelocityEngine();
> ve.setExtendedProperties(ep);
> Template tem== ve.getTemplate(EMail_Template);    /* EMail_Template is a
> String defined else where, and yes, its the right name */
>
> And it throws the error everytime at the last line.  I have no idea what
> I'm
> doing wrong, and I've read the online documentation several times and it
> doesn't seem to help.
> -Adam Cornett
>



-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com