动态更动Velocity模板路径

动态更改Velocity模板路径
///////////////////////////////////////////////////////  
        //其他方法: 1分别指定路径,此方法可以设定不同的路径 (也可是相对的。在eclipse下是工程目录)  
        try {  
            VelocityEngine velocityEngine = new VelocityEngine();  
            Properties properties = new Properties();  
            //也可以在这里指定绝对路径。当指定相对路径时, 在不同的环境下是有区别的。  
            //比如把程序部署到tomcat以后,相对路径相对到哪里是个很恶心的事情。  
            String basePath = "vm";  
            //可设置绝对路径  
            //String basePath = "F:/";  
            properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath);  
            velocityEngine.init(properties);  
            Template template = velocityEngine.getTemplate("example2.vm");  
            BufferedWriter writer = new BufferedWriter(  
                    new OutputStreamWriter(System.out));  
            template.merge(context, writer);  
            writer.flush();  
            writer.close();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  

 上面这段snapshot援引javaeye兄弟的一篇文章,主要是为了自己以后用的时候方便找,援引出处http://zhyt710.iteye.com/blog/235250