You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Michael Salmon <ms...@speakeasy.org> on 2005/02/20 18:46:47 UTC

tomcat 4.1.31 and velocity - template location problem

hi folks

I'm trying to get my development environment setup on freebsd and 
templates don't load from where I want. In particular here is what
I'm doing:

1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
override loadConfiguration()

2. In my webapp, web.xml I define the specific properties file:
    <param-name>org.apache.velocity.properties</param-name>
    <param-value>/WEB-INF/velocity.properties</param-value>

    I'm pretty sure the right velocity.properties file is being loaded, 
    because when I change the name it spits an error in the log.

4. In the properties file I define:

    file.resource.loader.path = /WEB-INF/templates/

5. In my servlet I do:
    getTemplate("Test.vm");

    /www/element/WEB-INF/templates/Test.vm - this file exists

6. catalina.log - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Test.vm'


7. If I copy my template to /www/element/Test.vm velocity finds the template, but I'd prefer not to keep my templates there. So any suggestion to make it load from the location I want but obvoiusly am setup wrong?

Thanks,
Michael

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


Re: tomcat 4.1.31 and velocity - template location problem

Posted by Nathan Bubna <nb...@gmail.com>.
beyond just the WebappLoader, the VelocityTools project is also home
to the VelocityViewServlet (designated successor of the deprecated
VelocityServlet), and several simple, drop-and-go example apps you can
play with until you get things working.

basically, if you're developing a webapp with Velocity, you should
look into the VelocityTools project.  it will make your life much
easier. :)

On Mon, 21 Feb 2005 11:47:32 +0200, Markos Charatzas <xa...@forthnet.gr> wrote:
> Hello Michael,
> 
> In a servlet environment I would recommed that you use a
> org.apache.velocity.tools.view.servlet.WebappLoader
> 
> with the loader.path specified as you have it already.
> 
> Have a good week :)
> Markos
> 
> On Sunday 20 February 2005 19:57, Michael Salmon wrote:
> > Just a follow-up. I found that from where I launch tomcat is where it
> > wants to load templates from. It seems clear to me my loader.path is not
> > being setup correctly. For now until I have a better solution I'll just
> > have to launch tomcat from my webapp root and put my templates there..
> > Still I'd love to have a proper solution.
> >
> > thanks
> > Michael
> >
> > On Sun, Feb 20, 2005 at 09:46:47AM -0800, Michael Salmon wrote:
> > > hi folks
> > >
> > > I'm trying to get my development environment setup on freebsd and
> > > templates don't load from where I want. In particular here is what
> > > I'm doing:
> > >
> > > 1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
> > > override loadConfiguration()
> > >
> > > 2. In my webapp, web.xml I define the specific properties file:
> > >     <param-name>org.apache.velocity.properties</param-name>
> > >     <param-value>/WEB-INF/velocity.properties</param-value>
> > >
> > >     I'm pretty sure the right velocity.properties file is being loaded,
> > >     because when I change the name it spits an error in the log.
> > >
> > > 4. In the properties file I define:
> > >
> > >     file.resource.loader.path = /WEB-INF/templates/
> > >
> > > 5. In my servlet I do:
> > >     getTemplate("Test.vm");
> > >
> > >     /www/element/WEB-INF/templates/Test.vm - this file exists
> > >
> > > 6. catalina.log -
> > > org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> > > resource 'Test.vm'
> > >
> > >
> > > 7. If I copy my template to /www/element/Test.vm velocity finds the
> > > template, but I'd prefer not to keep my templates there. So any
> > > suggestion to make it load from the location I want but obvoiusly am
> > > setup wrong?
> > >
> > > Thanks,
> > > Michael
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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


Re: tomcat 4.1.31 and velocity - template location problem

Posted by Markos Charatzas <xa...@forthnet.gr>.
Hello Michael,

In a servlet environment I would recommed that you use a 
org.apache.velocity.tools.view.servlet.WebappLoader

with the loader.path specified as you have it already.

Have a good week :)
Markos

On Sunday 20 February 2005 19:57, Michael Salmon wrote:
> Just a follow-up. I found that from where I launch tomcat is where it
> wants to load templates from. It seems clear to me my loader.path is not
> being setup correctly. For now until I have a better solution I'll just
> have to launch tomcat from my webapp root and put my templates there..
> Still I'd love to have a proper solution.
>
> thanks
> Michael
>
> On Sun, Feb 20, 2005 at 09:46:47AM -0800, Michael Salmon wrote:
> > hi folks
> >
> > I'm trying to get my development environment setup on freebsd and
> > templates don't load from where I want. In particular here is what
> > I'm doing:
> >
> > 1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
> > override loadConfiguration()
> >
> > 2. In my webapp, web.xml I define the specific properties file:
> >     <param-name>org.apache.velocity.properties</param-name>
> >     <param-value>/WEB-INF/velocity.properties</param-value>
> >
> >     I'm pretty sure the right velocity.properties file is being loaded,
> >     because when I change the name it spits an error in the log.
> >
> > 4. In the properties file I define:
> >
> >     file.resource.loader.path = /WEB-INF/templates/
> >
> > 5. In my servlet I do:
> >     getTemplate("Test.vm");
> >
> >     /www/element/WEB-INF/templates/Test.vm - this file exists
> >
> > 6. catalina.log -
> > org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> > resource 'Test.vm'
> >
> >
> > 7. If I copy my template to /www/element/Test.vm velocity finds the
> > template, but I'd prefer not to keep my templates there. So any
> > suggestion to make it load from the location I want but obvoiusly am
> > setup wrong?
> >
> > Thanks,
> > Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: tomcat 4.1.31 and velocity - template location problem

Posted by Nathan Bubna <nb...@gmail.com>.
personally, i think Markos gave you the best answer already.  you
should use the WebappLoader from the VelocityTools project.  The
FileResourceLoader that Velocity uses by default is not very webapp
friendly.  there are ways to get it working in web applications, but
in general they are not obvious and not portable.  use the
WebappLoader instead and what you're doing below should work fine.

On Mon, 21 Feb 2005 22:31:27 -0800, Michael Salmon <ms...@formulae.org> wrote:
> hi folks
> 
> my templates don't load from where I want. In particular here is what
> I'm doing:
> 
> 1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
> override loadConfiguration()
> 
> 2. In my webapp, web.xml I define the specific properties file:
>     <param-name>org.apache.velocity.properties</param-name>
>     <param-value>/WEB-INF/velocity.properties</param-value>
> 
>     I'm pretty sure the right velocity.properties file is being loaded,
>     because when I change the name it spits an error in the log.
> 
> 4. In the properties file I define:
> 
>     file.resource.loader.path = /WEB-INF/templates/
> 
> 5. In my servlet I do:
>     getTemplate("Test.vm");
> 
>     /www/element/WEB-INF/templates/Test.vm - this file exists
> 
> 6. catalina.log - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Test.vm'
> 
> I found that from where I launch tomcat is where velocity
> wants to load templates from. It seems clear to me my loader.path is not
> being setup correctly. For now until I have a better solution I'll just
> have to launch tomcat from my webapp root and put my templates there.. Still
> I'd love to have a proper solution.
> 
> Thanks,
> Michael
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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


Re: tomcat 4.1.31 and velocity - template location problem

Posted by Barbara Baughman <ba...@utdallas.edu>.
I haven't used VelocityServlet in a while, but as I recall you
needed to override the loadConfiguration method to properly configure
Velocity.  By default, Velocity thinks the template from a file
resource loader will be relative to the directory of the program that
is calling Velocity.  If you have Tomcat calling Velocity, then it
runs from $TOMCAT_HOME/bin.  You'll need to change that in
loadConfiguration, declaring the file resource loader path
specifically instead of accepting the default.  I think there is an
example program that does this provided with Velocity.  It's NOT
intuitively obvious.

But, for the long term, since VelocityServlet will be deprecated soon,
you should really be looking at the Velocity Tools project, which is
specifically designed for web applications.  It may look to be a
project that is "unofficially" attached to Velocity development, but
in fact it is a project that is widely recognized, used, and supported
by the Velocity community for web development.  The Velocity home page
recognizes it as a subproject of Velocity.

Welcome to Velocity.  Despite your initial frustration (been there,
done that), you are going to LOVE using it once you get the first
servlet running.

Barbara Baughman
X2157

On Mon, 21 Feb 2005, Michael Salmon wrote:

> hi folks
>
> my templates don't load from where I want. In particular here is what
> I'm doing:
>
> 1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
> override loadConfiguration()
>
> 2. In my webapp, web.xml I define the specific properties file:
>     <param-name>org.apache.velocity.properties</param-name>
>     <param-value>/WEB-INF/velocity.properties</param-value>
>
>     I'm pretty sure the right velocity.properties file is being loaded,
>     because when I change the name it spits an error in the log.
>
> 4. In the properties file I define:
>
>     file.resource.loader.path = /WEB-INF/templates/
>
> 5. In my servlet I do:
>     getTemplate("Test.vm");
>
>     /www/element/WEB-INF/templates/Test.vm - this file exists
>
> 6. catalina.log - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Test.vm'
>
> I found that from where I launch tomcat is where velocity
> wants to load templates from. It seems clear to me my loader.path is not
> being setup correctly. For now until I have a better solution I'll just
> have to launch tomcat from my webapp root and put my templates there.. Still
> I'd love to have a proper solution.
>
> Thanks,
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


tomcat 4.1.31 and velocity - template location problem

Posted by Michael Salmon <ms...@formulae.org>.
hi folks

my templates don't load from where I want. In particular here is what
I'm doing:

1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
override loadConfiguration()

2. In my webapp, web.xml I define the specific properties file:
    <param-name>org.apache.velocity.properties</param-name>
    <param-value>/WEB-INF/velocity.properties</param-value>

    I'm pretty sure the right velocity.properties file is being loaded, 
    because when I change the name it spits an error in the log.

4. In the properties file I define:

    file.resource.loader.path = /WEB-INF/templates/

5. In my servlet I do:
    getTemplate("Test.vm");

    /www/element/WEB-INF/templates/Test.vm - this file exists

6. catalina.log - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Test.vm'

I found that from where I launch tomcat is where velocity
wants to load templates from. It seems clear to me my loader.path is not
being setup correctly. For now until I have a better solution I'll just
have to launch tomcat from my webapp root and put my templates there.. Still
I'd love to have a proper solution.

Thanks,
Michael

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


Re: tomcat 4.1.31 and velocity - template location problem

Posted by Michael Salmon <ms...@formulae.org>.
Just a follow-up. I found that from where I launch tomcat is where it
wants to load templates from. It seems clear to me my loader.path is not
being setup correctly. For now until I have a better solution I'll just
have to launch tomcat from my webapp root and put my templates there.. Still
I'd love to have a proper solution.

thanks
Michael

On Sun, Feb 20, 2005 at 09:46:47AM -0800, Michael Salmon wrote:
> hi folks
> 
> I'm trying to get my development environment setup on freebsd and 
> templates don't load from where I want. In particular here is what
> I'm doing:
> 
> 1. servlet extends VelocityServlet. and calls Velocity.init(). I dont
> override loadConfiguration()
> 
> 2. In my webapp, web.xml I define the specific properties file:
>     <param-name>org.apache.velocity.properties</param-name>
>     <param-value>/WEB-INF/velocity.properties</param-value>
> 
>     I'm pretty sure the right velocity.properties file is being loaded, 
>     because when I change the name it spits an error in the log.
> 
> 4. In the properties file I define:
> 
>     file.resource.loader.path = /WEB-INF/templates/
> 
> 5. In my servlet I do:
>     getTemplate("Test.vm");
> 
>     /www/element/WEB-INF/templates/Test.vm - this file exists
> 
> 6. catalina.log - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Test.vm'
> 
> 
> 7. If I copy my template to /www/element/Test.vm velocity finds the template, but I'd prefer not to keep my templates there. So any suggestion to make it load from the location I want but obvoiusly am setup wrong?
> 
> Thanks,
> Michael

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