import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloWorld
{
public static void main( String[] args )
throws Exception
{
/* first, get and initialize an engine */
VelocityEngine ve = new VelocityEngine();
ve.init();
/* next, get the Template */
Template t = ve.getTemplate( "helloworld.vm" );
/* create a context and add data */
VelocityContext context = new VelocityContext();
context.put("name", "World");
/* now render the template into a StringWriter */
StringWriter writer = new StringWriter();
t.merge( context, writer );
/* show the World */
System.out.println( writer.toString() );
}
}
这篇文章译自javaWord上面的《Start up the velocity Template Engine》 By Geir Magnusson Jr., JavaWorld.com, 12/28/01Velocity是一个由互联网上的自愿者开发的开源模板工具,现在由Apache软件基金会下的jakarta项目管理。在Jakarta Velocity Project网站上,你可以随意下