You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by AngeloChen960 <an...@gmail.com> on 2008/01/15 09:30:46 UTC

template in a Tapestry 5 app

Hi,

how Velocity locates template file in a web app? here is what I did:

in the WEB-INF i have a velocity.properties with following content:
resource.loader = file
file.resource.loader.path = /tmp

and I put a .vm file in /tmp

in the code, I did:
  Template t = ve.getTemplate("registrationEmail.vm");

but always got the exception:ResourceNotFoundException

why?

Thanks


-- 
View this message in context: http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14833725.html
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Re: template in a Tapestry 5 app

Posted by AngeloChen960 <an...@gmail.com>.
Hi Nathan,
Thanks, ClassPathResourceLoader does the job.
a.c.


Nathan Bubna wrote:
> 
> If you need to access templates (aka vm files) from within a webapp,
> you should use the WebappLoader provided as part of the VelocityTools
> project.  Velocity itself (and especially the FileResourceLoader,
> which is the default resource loader) is completely clueless about
> webapps.
> 
> If you have some opposition to using the webapp support in
> VelocityTools and really insist on just using plain Velocity itself,
> then you will probably want to use the ClasspathResourceLoader and put
> your templates in the classpath.  The FileResourceLoader is really not
> meant to be used with webapps.
> 
> 

-- 
View this message in context: http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14873593.html
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Re: template in a Tapestry 5 app

Posted by Nathan Bubna <nb...@gmail.com>.
If you need to access templates (aka vm files) from within a webapp,
you should use the WebappLoader provided as part of the VelocityTools
project.  Velocity itself (and especially the FileResourceLoader,
which is the default resource loader) is completely clueless about
webapps.

If you have some opposition to using the webapp support in
VelocityTools and really insist on just using plain Velocity itself,
then you will probably want to use the ClasspathResourceLoader and put
your templates in the classpath.  The FileResourceLoader is really not
meant to be used with webapps.

If, for some obscure reason, you really want to use the
FileResourceLoader, then you will need to either figure out what the
JVM your webapp is running in considers the "current directory" and
put your templates there or else you will actually need to configure
the file.resource.loader.path to an absolute path and put your
templates there.

These are most of your options.  I highly recommend you just add
VelocityTools (particularly the velocity-view-1.4.jar) to your webapp
and tell velocity to use the WebappLoader as the resource loader).  If
you need more specific instructions on how to do this, then search the
mailing list archives (velocity.markmail.org) or read the
documentation or ask on this list.

On Jan 15, 2008 4:37 PM, AngeloChen960 <an...@gmail.com> wrote:
>
> Hi,
>
> Actually I don't need absolute path,  I only need to access vm files inside
> the web app, any idea where is the good location to place those *.vm files
> so that getTemplate can find them?
>
> A.C.
>
>
>
> Nathan Bubna wrote:
> >
> > The FileResourceLoader is very difficult to use in a webapp.  We
> > recommend that you use the WebappResourceLoader (aka WebappLoader)
> > that is provided by the VelocityTools library instead.
> >
> > If you really want to use the FileResourceLoader, then the problem is
> > likely that you need to use an absolute path as the value for
> > file.resource.loader.path, instead of a relative path.
> >
> > Also consider reading:
> > http://velocity.apache.org/engine/releases/velocity-1.5/webapps.html
> >
> > On Jan 15, 2008 12:30 AM, AngeloChen960 <an...@gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> how Velocity locates template file in a web app? here is what I did:
> >>
> >> in the WEB-INF i have a velocity.properties with following content:
> >> resource.loader = file
> >> file.resource.loader.path = /tmp
> >>
> >> and I put a .vm file in /tmp
> >>
> >> in the code, I did:
> >>   Template t = ve.getTemplate("registrationEmail.vm");
> >>
> >> but always got the exception:ResourceNotFoundException
> >>
> >> why?
> >>
> >> Thanks
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14833725.html
> >> Sent from the Velocity - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >> For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14855254.html
>
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: template in a Tapestry 5 app

Posted by AngeloChen960 <an...@gmail.com>.
Hi,

Actually I don't need absolute path,  I only need to access vm files inside
the web app, any idea where is the good location to place those *.vm files
so that getTemplate can find them?

A.C.


Nathan Bubna wrote:
> 
> The FileResourceLoader is very difficult to use in a webapp.  We
> recommend that you use the WebappResourceLoader (aka WebappLoader)
> that is provided by the VelocityTools library instead.
> 
> If you really want to use the FileResourceLoader, then the problem is
> likely that you need to use an absolute path as the value for
> file.resource.loader.path, instead of a relative path.
> 
> Also consider reading:
> http://velocity.apache.org/engine/releases/velocity-1.5/webapps.html
> 
> On Jan 15, 2008 12:30 AM, AngeloChen960 <an...@gmail.com> wrote:
>>
>> Hi,
>>
>> how Velocity locates template file in a web app? here is what I did:
>>
>> in the WEB-INF i have a velocity.properties with following content:
>> resource.loader = file
>> file.resource.loader.path = /tmp
>>
>> and I put a .vm file in /tmp
>>
>> in the code, I did:
>>   Template t = ve.getTemplate("registrationEmail.vm");
>>
>> but always got the exception:ResourceNotFoundException
>>
>> why?
>>
>> Thanks
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14833725.html
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14855254.html
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Re: template in a Tapestry 5 app

Posted by Nathan Bubna <nb...@gmail.com>.
The FileResourceLoader is very difficult to use in a webapp.  We
recommend that you use the WebappResourceLoader (aka WebappLoader)
that is provided by the VelocityTools library instead.

If you really want to use the FileResourceLoader, then the problem is
likely that you need to use an absolute path as the value for
file.resource.loader.path, instead of a relative path.

Also consider reading:
http://velocity.apache.org/engine/releases/velocity-1.5/webapps.html

On Jan 15, 2008 12:30 AM, AngeloChen960 <an...@gmail.com> wrote:
>
> Hi,
>
> how Velocity locates template file in a web app? here is what I did:
>
> in the WEB-INF i have a velocity.properties with following content:
> resource.loader = file
> file.resource.loader.path = /tmp
>
> and I put a .vm file in /tmp
>
> in the code, I did:
>   Template t = ve.getTemplate("registrationEmail.vm");
>
> but always got the exception:ResourceNotFoundException
>
> why?
>
> Thanks
>
>
> --
> View this message in context: http://www.nabble.com/template-in-a-Tapestry-5-app-tp14833725p14833725.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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