我在网上找了好多,例子都是相同的 代码如下
一、HelloVelocity.java
package My;
import java.io.StringWriter;import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloVelocity {

public static void main(String[] args) throws Exception
    {
        /*  first, get and initialize an engine  */
        VelocityEngine engine = new VelocityEngine();
        engine.init();        /*  next, get the Template  */
        Template template = engine.getTemplate( "helo.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();
        template.merge( context, writer );        /* display the results */
        System.out.println( writer.toString() );    
    }    }
二、helo.vm
Welcome $name to wuweishe.blogchina.com! 
这两个文件都放在src\My 下面。velocity-1.6.1.jar
velocity-1.6.1-dep.jar
也放到 web-inf/lib下面了但是运行时出错。
Exception in thread "main" org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.
at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
at My.HelloVelocity.main(HelloVelocity.java:15)
Caused by: java.lang.UnsupportedOperationException: Could not retrieve ServletContext from application attributes
at org.apache.velocity.runtime.log.ServletLogChute.init(ServletLogChute.java:73)
at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
... 5 more
我该怎么办呀??