velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@adeptra.com>
Subject Re: JBoss3.0/Tomcat & Velocity works; template caching question
Date Wed, 10 Jul 2002 10:09:57 GMT
On 7/10/02 3:06 AM, "Milo" <msimpson@kikkoman.org> wrote:

> 
> I would like to verify that in a servlet environment, if your servlet
> runner does not expand your war/jar file during deployment *cough*
> Tomcat 4.0 *cough*, then you cannot use the "file resource loader"
> because "String root = getServletContext().getRealPath(value)" returns
> null as there is to RealPath war file uwrapped in memory.  Correct?

*cough* yep *cough*.

:)

Why are we coughing?

> 
> Secondly, the classpath and WebappLoaders do not cache templates.
> Correct?   Both of them return 0 for getLastModified(Resource).  This
> means that if you use the classpath loader, then every time your
> template is accessed it has to be reparsed by the engine, Correct?

While your statement isn't 'pedantically true' (because loaders don't
cache), they aren't able to figure out if the resource has changed, so that
have to indicate that the resource has when asked.

I've worried about this (not too hard, obviously :) and I can't find a good
solution other than make the resource manager have a setting that keeps it
from asking the loader if changed for some fixed amount of time - so in a
production deployment where the template won't change, it would just get a
resource and keep it.  (You could make this fancier w/ app attributes,
allowing for hot deployment of new templates, if needed...)

> I don't mind reloading on every access during development (great for
> editing templates, see below), but what do I do for deployment?  Note I
> can't ditch JBoss and use a standalone servlet runner that will unpack
> the war file as I will be talking to ejbs, and I'd like to keep
> everything in one vm for speed.
> 
> 
> JBoss 3.0 with Tomcat and Velocity:
> Using the classpath loader, putting my template files in jar, and then
> placing that jar in the WEB-INF/lib dir, I can access the template files
> from my servlet.   My war file thus looks like this:
> mysite.war
>   +---WEB-INF
>   |      +---lib
>   |      |     +---templates.jar  <--- all the .vm files
>   |      |     |...jar
>   |      |
>   |      +---classes
>   |            +---myServlet.class
>   |            |...
>   |           
> This works, but is a pain wrt template development, eg you need to
> jar/war & redeploy everytime you want to see a template change.

I tend to do the same thing.

> 
> So, for development what I do is I deploy my templates.jar into JBoss
> separately, eg remove templates.jar from mysite.war and deploy both of
> them into JBoss.  JBoss puts everything in the same "class-space" so it
> works nicely.  Thus to "deploy" I put mysite.war and templates.jar in my
> jboss/server/default/deploy dir.  Then all I need to do during
> development is rejar and redrop the templates.
> I can actually go a step further and avoid having to jar the templates
> at all, by building a jar structure in the JBoss deploy directory.  Eg
> "mkdir server/default/deploy/templates.jar ; cp *.vm
> server/default/deploy/templates.jar".  Then I can just updated/edit
> individual tempates without having to package or restart anything.
> That is what made be start to wonder about velocity's cacheing  wrt to
> the classpath loader.

That's a really cute technique.  A little disturbing, but cute.  Any chance
you could write that up and we can add to our notes in the dev guide on
working with servlet containers?  I assume it works for tomcat alone?

> 
> Note that I tried deploying my war file unpacked into jboss using the
> "mkdir mysite.war" that doesn't work as Tomcat will slurps the
> .jar,.class,.jsp files over to a work dir that ends up being the "RealPath".
> 

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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


Mime
View raw message