velocity的默认加载路径修改

package  com.yaday.test;

import  java.io.StringWriter;
import  java.util.Properties;

import  org.apache.velocity.Template;
import  org.apache.velocity.VelocityContext;
import  org.apache.velocity.app.Velocity;
import  org.apache.velocity.app.VelocityEngine;
import  org.junit.Test;

public   class  VelocityTest  {
    @Test 
public void testVelocity(){
        
try {
            VelocityEngine ve 
= new VelocityEngine();
            ve.setProperty(
"resource.loader" , "class");
            ve.setProperty(
"class.resource.loader.class""org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
            ve.init();
            Template template
=null;
            template
=ve.getTemplate("velocity/first.vm");

            VelocityContext context
=new VelocityContext();
            context.put(
"name"new String("jimphei"));
            
        
            

            StringWriter sw
=new StringWriter();
            template.merge(context, sw);
            System.out.println(sw.toString());
        }
 catch (Exception e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

你可能感兴趣的:(java,apache,velocity,JUnit)