You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Milo <ms...@kikkoman.org> on 2002/07/10 09:06:37 UTC

JBoss3.0/Tomcat & Velocity works; template caching question

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?

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?

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.

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.

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".

Thanks.

Milo S.







--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JBoss3.0/Tomcat & Velocity works; template caching question

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/10/02 10:15 PM, "Milo" <ms...@kikkoman.org> wrote:
> 
> Answered my own question.
> 
> Printed out the Velocity Developer's Guide and had a nice little sit
> down and end-to-end read somewhere where I wouldn't be distracted by the
> computer, Starbucks!  Sections 10 and 12 answered my question;
> "<loader_name>.resource.loader.cache = false".  Bingo.

That doesn't work for me when the Starbucks has the wireless service
(whatever it's called now...)

Glad all is well.

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



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JBoss3.0/Tomcat & Velocity works; template caching question

Posted by Milo <ms...@kikkoman.org>.
>
>
>> Yeah, dled Tomcat by itself and gave it a shot.  The trick is to 
>> creatively use Tomcat's classloader hierarchy.  Note for everybody 
>> else this is only for development time.  For deployment you should 
>> put your templates in with your webapp.
>
>
> From 
> http://jakarta.apache.org/tomcat/tomcat-4.0-doc/class-loader-howto.html.
>
> ClassLoader Hierarchy
>      Bootstrap
>          |
>       System
>          |
>       Common
>      /      \
> Catalina   Shared   <--- put your velocity templates here, non-jared
>              |  |          eg, |$CATALINA_HOME/classes|
>             /   \
>        Webapp1  Webapp2 ...
>
> I'll write something up this weekend.
>
> Back to the caching question wrt to the classpath loader:  How do 
> specify the "don't reload my templates"; property the 
> velocity.properties file?  I think the default caching behavior of the 
> classpath loader needs to be documented/broadcast further.  All I've 
> seen wrt the classpath loader is how to get it working.  ;)  And I bet 
> there are people running the classpath loader in production doing mad 
> template reparsing.


Answered my own question.

Printed out the Velocity Developer's Guide and had a nice little sit 
down and end-to-end read somewhere where I wouldn't be distracted by the 
computer, Starbucks!  Sections 10 and 12 answered my question; 
"<loader_name>.resource.loader.cache = false".  Bingo.  

Milo S.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JBoss3.0/Tomcat & Velocity works; template caching question

Posted by Milo <ms...@kikkoman.org>.
>
>
>  
>
>>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?
>  
>
Yeah, dled Tomcat by itself and gave it a shot.  The trick is to 
creatively use Tomcat's classloader hierarchy.  Note for everybody else 
this is only for development time.  For deployment you should put your 
templates in with your webapp.

 From 
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/class-loader-howto.html.

 ClassLoader Hierarchy
      Bootstrap
          |
       System
          |
       Common
      /      \
 Catalina   Shared   <--- put your velocity templates here, non-jared
              |  |          eg, |$CATALINA_HOME/classes|
             /   \
        Webapp1  Webapp2 ... 


I'll write something up this weekend.

Back to the caching question wrt to the classpath loader:  How do 
specify the "don't reload my templates"; property the 
velocity.properties file?  I think the default caching behavior of the 
classpath loader needs to be documented/broadcast further.  All I've 
seen wrt the classpath loader is how to get it working.  ;)  And I bet 
there are people running the classpath loader in production doing mad 
template reparsing.

Milo S.







--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JBoss3.0/Tomcat & Velocity works; template caching question

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/10/02 3:06 AM, "Milo" <ms...@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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>