You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Tim Colson <tc...@cisco.com> on 2004/08/18 03:08:03 UTC

VelocityViewServlet and Jar resources?

Say, will VelocityViewServlet automagically pull in templates & macros from
a JAR dropped inside WEB-INF\lib? 

Timo


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


Using both Jar and Webapp resource paths

Posted by Tim Colson <tc...@cisco.com>.
Nathan said:
> if there's ... no resource loader specified in the
> velocity.properties file, then the WebappLoader is used. 
> otherwise, if resource loader(s)
> is/are specified in whatever properties file the user tells 
> the VVS to use, the VVS will use that/those resource loader(s).

I'm trying to setup a dev environment where include paths can stay the same
for local files, as well as later when I bundle up the 'common'
layout/macros into a JAR. That jar will be shared among other projects. (Try
THAT, JSP! <grin>)

I have dual loaders working for VelocityViewServlet:

#---------------------------------------------------------------------------
-
# RESOURCE loaders
#---------------------------------------------------------------------------
-
resource.loader = class, webapp
#
# ClasspathResourceLoader
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
# WebappResourceLoader
webapp.resource.loader.description = Velocity Webapp Resource Loader
webapp.resource.loader.class=org.apache.velocity.tools.view.servlet.WebappLo
ader

To make paths work in either case, I added template directories into the
classpath. Works great to resolve "common/footer.vm" in
WEB-INF/templates/vm/common/footer.vm or inside a bundled common-ui.jar. I
looked at the WebappLoader and it seems the same functionality can be setup
in the config with webapp.resource.loader.path. 

Spiffy.  In fact, it works so well, I'm kind of spoiled now. <grin>

So just wanted to say my hats off to Geir/Nathan/Gabe/Marino and everyone
else for continuing to surprise me with code that Just Works. :-)

Cheers,
Timo











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


Re: VelocityViewServlet and Jar resources?

Posted by Nathan Bubna <na...@esha.com>.
Claude Brisson said:
> Nathan wrote :
>
> > no need to subclass.  the VVS gives priority to your velocity.properties
by
> > loading them after setting the defaults.  so you can use any of the other
> > resource loaders (classpath, jar, file, url, whatever) without
subclassing.
> >
>
> Ok, my mistake.
> It's the same behaviour for the log system class, isn't it ?

yep.

> This means that if people don't comment the default FileResourceLoader
> in the initial velocity.properties, then the WebappLoader won't be used,
> or am I wrong ?

not sure what you mean by "initial velocity.properties", but i mean what i
said.  if there's no properties file or no resource loader specified in the
properties file, then the WebappLoader is used.  it is the default,
out-of-the-box behavior of the VVS.  otherwise, if (a) resource loader(s)
is/are specified in whatever properties file the user tells the VVS to use,
the VVS will use that/those resource loader(s).

> Shouldn't we provide a proper velocity.properties a the root of the tools
tarball ?

to fix what problem?  it ain't broke right now, so...

Nathan Bubna
nathan@esha.com


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


Re: VelocityViewServlet and Jar resources?

Posted by Claude Brisson <cl...@renegat.net>.
Nathan wrote :

> no need to subclass.  the VVS gives priority to your velocity.properties by
> loading them after setting the defaults.  so you can use any of the other
> resource loaders (classpath, jar, file, url, whatever) without subclassing.
> 

Ok, my mistake.
It's the same behaviour for the log system class, isn't it ?

This means that if people don't comment the default FileResourceLoader
in the initial velocity.properties, then the WebappLoader won't be used,
or am I wrong ?

Shouldn't we provide a proper velocity.properties a the root of the tools tarball ?

Claude


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


RE: VelocityViewServlet and Jar resources?

Posted by Tim Colson <tc...@cisco.com>.
Thanks gents, this helps me out. 

Last I checked JSP files cannot be bundled/loaded from a .jar -- and I'm
looking at creating a library of layouts/macros to distribute to multiple
app owners. The trick will be if I can load from the common library jar +
app specific files during DEV, and then two jars during deployment. I'll try
it out and see for myself. :-)

BTW -- apologies for slipping up and sending initially to velocity-dev
instead of -user. 

Cheers,
Tim



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


Re: VelocityViewServlet and Jar resources?

Posted by Nathan Bubna <na...@esha.com>.
Claude Brisson said:
> I don't think so, because the default resource loader used by the VVS is the
WebappResourceLoader,
> which uses the method ServletContext.getResourceAsStream( ).

correct.

> I'm afraid this is hardcoded... (but how to bypass the defaults defined in
the core ?)

you override the defaults by specifying your own resource loader(s) in your
velocity.properties file.

> But it can be subclassed to use the ClasspathResourceLoader (or even both
loaders).

no need to subclass.  the VVS gives priority to your velocity.properties by
loading them after setting the defaults.  so you can use any of the other
resource loaders (classpath, jar, file, url, whatever) without subclassing.

> Claude
>
> ----- Original Message ----- 
> From: "Tim Colson" <tc...@cisco.com>
> To: "'Velocity Developers List'" <ve...@jakarta.apache.org>
> Sent: Wednesday, August 18, 2004 3:08 AM
> Subject: VelocityViewServlet and Jar resources?
>
>
> > Say, will VelocityViewServlet automagically pull in templates & macros
from
> > a JAR dropped inside WEB-INF\lib?
> >
> > Timo

Nathan Bubna
nathan@esha.com


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


Re: VelocityViewServlet and Jar resources?

Posted by Claude Brisson <cl...@renegat.net>.
I don't think so, because the default resource loader used by the VVS is the WebappResourceLoader,
which uses the method ServletContext.getResourceAsStream( ).

I'm afraid this is hardcoded... (but how to bypass the defaults defined in the core ?)

But it can be subclassed to use the ClasspathResourceLoader (or even both loaders).

Claude

----- Original Message ----- 
From: "Tim Colson" <tc...@cisco.com>
To: "'Velocity Developers List'" <ve...@jakarta.apache.org>
Sent: Wednesday, August 18, 2004 3:08 AM
Subject: VelocityViewServlet and Jar resources?


> Say, will VelocityViewServlet automagically pull in templates & macros from
> a JAR dropped inside WEB-INF\lib? 
> 
> Timo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 

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