`
takkymj
  • 浏览: 124216 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Velocity中加载vm文件的三种方式

阅读更多
Velocity中加载vm文件的三种方式:



方式一:加载classpath目录下的vm文件

Properties p = new Properties();

p.put("file.resource.loader.class",

"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

Velocity.init(p);

...

Velocity.getTemplate(templateFile);





方式二:根据绝对路径加载,vm文件置于硬盘某分区中,如:d:\\tree.vm

Properties p = new Properties();

p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "d:\\");

Velocity.init(p);

...

Velocity.getTemplate("tree.vm");





方式三:使用文本文件,如:velocity.properties,配置如下:

input.encoding = UTF-8

file.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader



再利用如下方式进行加载

Properties p = new Properties();

p.load(this.getClass().getResourceAsStream("/velocity.properties"));

Velocity.init(p);

...

Velocity.getTemplate(templateFile);





本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kdevn/archive/2009/02/04/3862946.aspx
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics