You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jorge Andres Vasquez <JV...@psl.com.co> on 2004/04/19 21:38:49 UTC

Velocity Deployment in Application Server...

Greetings to everyone,

I am currently trying to deploy velocity in Tomcat, and would like to know if its possible to set a relative path property for the template loader.  Currently I´m using the ServletContext object which returns the absolute path of the directory where I'm keeping the macros (see the code fragment that appears ahead).  The problem is that I have to deploy this into a proprietary framework which works as the controller for the MVC pattern where it is difficult to access the context object.  
How can I configure the Velocity Resource Loader to use a relative directory?
Other question that I have is what are the advantages of using the implicit 
Loaders that come with Velocity instead of using my own StringBuffer reader for example to read the contents of a template?
And finally, last question is related to the cache process of the templating engine, how can I control it (reload a specific template)?, how often and based on what criteria does it reloads the contents of a template?


String path = context.getRealPath("/bancodecredito/macros/");
//The previous returns something like this:  C:\jakarta-tomcat-//4.1.29\webapps\bancodecredito\bancodecredito\macros....which is just fine //so far...
Properties p = new Properties();
p.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH,  path );
p.setProperty( "runtime.log", path + "velocity.log" );
try {
	Velocity.init(p);
} catch (Exception e2) {
	e2.printStackTrace();
}


Thanks a lot for your valuable time.

Jorge Andrés Vásquez
Analista de Desarrollo 
PSL-Medellin



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


Re: Velocity Deployment in Application Server...

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Jorge,

Try posting this to the list velocity-user@jakarta.apache.org.  That list is
devoted to answering user questions.  This one is more oriented towards the
developers of Velocity (e.g. those creating the component, not the
developers using the component).

With your code example, you can set the FILE_RESOURCE_LOADER_PATH to the
root of your webapp, which you can typically get with
servletcontext.getRelativePath("/").  Or subclass the VelocityViewServlet
from the velocity-tools subproject.  This handles this for you automatically
(and a whole lot else besides).

To answer your second question, the main advantage of using the resource
managers that come with Velocity (as opposed to just calling
Velocity.evaluate on a String) is that (A) they're easier to work with when
accessing a large pool of source files, and  (B) templates can be cached
resulting in better performance.

If you have more questions, I'll answer in the velocity-user list.

Best regards, WILL

----- Original Message ----- 
From: "Jorge Andres Vasquez" <JV...@psl.com.co>
To: <ve...@jakarta.apache.org>
Sent: Monday, April 19, 2004 12:38 PM
Subject: Velocity Deployment in Application Server...


Greetings to everyone,

I am currently trying to deploy velocity in Tomcat, and would like to know
if its possible to set a relative path property for the template loader.
Currently I´m using the ServletContext object which returns the absolute
path of the directory where I'm keeping the macros (see the code fragment
that appears ahead).  The problem is that I have to deploy this into a
proprietary framework which works as the controller for the MVC pattern
where it is difficult to access the context object.
How can I configure the Velocity Resource Loader to use a relative
directory?
Other question that I have is what are the advantages of using the implicit
Loaders that come with Velocity instead of using my own StringBuffer reader
for example to read the contents of a template?
And finally, last question is related to the cache process of the templating
engine, how can I control it (reload a specific template)?, how often and
based on what criteria does it reloads the contents of a template?


String path = context.getRealPath("/bancodecredito/macros/");
//The previous returns something like this:
C:\jakarta-tomcat-//4.1.29\webapps\bancodecredito\bancodecredito\macros....w
hich is just fine //so far...
Properties p = new Properties();
p.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH,  path );
p.setProperty( "runtime.log", path + "velocity.log" );
try {
Velocity.init(p);
} catch (Exception e2) {
e2.printStackTrace();
}


Thanks a lot for your valuable time.

Jorge Andrés Vásquez
Analista de Desarrollo
PSL-Medellin



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