Of course, looking for cases of the big people generally want to go directly to a case on the line, not a lot of time to read a lot of text, so not long-winded.
One of course first to download velocity required jar bag, everywhere there are downloads of course I'm going to the official download, after all, the official things are generally more formal
To say the Apache official, think of just start out to work in the basic daily in the official Apache website click less than 50 times. Open source is a lot of things, although the English is rather rotten. But see more
Later found that it is so simple so here I suggest that the best to read the English document, see more of the truth is the same.
Address http://velocity.apache.org/download.cgi I downloaded the latest version Velocity-1.7.zip
Two new Java project my project name here is Velocityexample, then create a new package named Com.qiailin.example, and create a new class under the package Velocityexample.java
[Java] View plain copy print? package com.qiailin.example; import java.io.stringwriter; Import org.apache.velocity.Template; import org.apache.velocity.velocitycontext; import org.apache.velocity.app.velocity; import org.apache.velocity.app.velocityengine; /** * 2011 Year January 14 13:23:13 * @author paint Erlend * VelocityExample * Email:qiailing.ok@163.com * qq 172794299 */ public class velocityexample { /** * @param args */ public static void main (String[] args) { new velocityexample (). VelociTyclassloadexample (); } public void velocityclassloadexample () { // Create engine velocityengine ve=new velocityengine (); //Set the template load path, which is set under class ve.setproperty (velocity.resource_loader, " Class "); ve.setproperty (" Class.resource.loader.class ", " Org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader "); try { //initialization Operations ve.init (); //load template, set template coding template t=ve.gettemplate (" QIAILIN.VM "," GBK "); //Set initialization data velocitycontext context = new velocitycontext (); context.put ("name", "John"); Context.put ("project", Velo)City "); / /Set Output Stringwriter writer = new stringwriter (); //the environment data into the output t.merge (Context, writer); &nbs