You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Shahar Solomianik <sh...@tikalknowledge.com> on 2001/01/17 21:19:26 UTC

Multiple templates location/VelocityServlet instances

Hi velocity list, its me again.

Since currently im not deploying templates in EAR files ...
I have several web contexts in my tomcat server, and I want each contexts
templates to be loaded from a different path.
what are my options ?

I see that even though I supply different velocity.properties file for each
context, each containing another setting for
resource.loader.1.resource.path, only the first context to be run loads the
prop file so it looks for templates only in one place (I guess the servlet
checks to see if it has already loaded the file).

So, in other words, How do I start more than one VelocityServlet on a
servlet runner ?

Shahar.


Re: Multiple templates location/VelocityServlet instances

Posted by Rafal Krzewski <Ra...@e-point.pl>.
"Geir Magnusson Jr." wrote:

> Not entirely true, I think.  If you drop velocity.jar into tomcat/lib
> rather than into  WEB-INF/lib, then all servlets that use vel would be
> sharing the same instance of the velocity Runtime because the 'system'
> classloader rather than the webapp classloader would provide it.
> 
> So the first servlet that calls Runtime.init( props ) does the setup,
> and the rest live with it.
> 
> Right?

Right! This was probably the problem that Shahar was facing.

Be very careful about what jar files you put into Java classpath and
Tomcat lib/ directory. For example turbine.jar and velocity.jar should 
NOT be put in there. Put them in <context>/WEB-INF/lib dirs instead.

As a rule of thumb, all of the jar files that the application depends
on (except java rt.jar and servlet-api.jar/j2ee.jar) should be put into
webapp/WEB-INF/lib directory. Even if this means duplication of files
among multiple apps, it will save you a lot of trouble.

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

Re: Multiple templates location/VelocityServlet instances

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Rafal Krzewski wrote:
> 
> Shahar Solomianik wrote:
> 
> > I see that even though I supply different velocity.properties file for each
> > context, each containing another setting for
> > resource.loader.1.resource.path, only the first context to be run loads the
> > prop file so it looks for templates only in one place (I guess the servlet
> > checks to see if it has already loaded the file).
> >
> > So, in other words, How do I start more than one VelocityServlet on a
> > servlet runner ?
> 
> An answer to you earlier question - 'webapp' is alias for the root
> directory
> of a WAR file, or a tomcat context.
> 
> What you are saying above sounds plain werid. Each context has a
> different
> class loader, and thus a separate JVM sandbox. Class objects exist
> idepenently
> in each sandbox, so there is no way that an instance VelocityServlet in
> one
> context could influence VelocityServlets in other conetxts.

Not entirely true, I think.  If you drop velocity.jar into tomcat/lib
rather than into  WEB-INF/lib, then all servlets that use vel would be
sharing the same instance of the velocity Runtime because the 'system'
classloader rather than the webapp classloader would provide it.

So the first servlet that calls Runtime.init( props ) does the setup,
and the rest live with it.

Right?

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: Multiple templates location/VelocityServlet instances

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Shahar Solomianik wrote:

> I see that even though I supply different velocity.properties file for each
> context, each containing another setting for
> resource.loader.1.resource.path, only the first context to be run loads the
> prop file so it looks for templates only in one place (I guess the servlet
> checks to see if it has already loaded the file).
> 
> So, in other words, How do I start more than one VelocityServlet on a
> servlet runner ?

An answer to you earlier question - 'webapp' is alias for the root
directory 
of a WAR file, or a tomcat context.

What you are saying above sounds plain werid. Each context has a
different
class loader, and thus a separate JVM sandbox. Class objects exist
idepenently
in each sandbox, so there is no way that an instance VelocityServlet in
one 
context could influence VelocityServlets in other conetxts.

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl