Strictly Programming

Using Velocity in a Tapestry 5 app:

Posted in Tapestry 5 by sqllyw on 12/08/2008

1. Declare dependency in pom.xml


2. Put sample.vm file under resources directory

3. Add following code:

Properties p = new Properties();
p.setProperty("resource.loader", "class");

VelocityEngine ve = new VelocityEngine();

try {
	Template t = ve.getTemplate("sample.vm");
    VelocityContext context = new VelocityContext();
    context.put("name", "World");
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
catch( ResourceNotFoundException rnfe ) {
  	System.out.println("cant find template");
catch (Exception e) {

If you use IDEA to build, update the IDE setting to include *.vm as resources pattern too.(setting/compiler/resources patterns)

generate a Tapestry 5.0.18 project
mvn archetype:create -DarchetypeGroupId=org.apache.tapestry -DarchetypeArtifactId=quickstart -DgroupId=org.apache.tapestry -DartifactId=tutorial -DpackageName=org.apache.tapestry5.tutorial -DarchetypeVersion=5.0.18


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: