Velocity中加载vm文件的三种方式
2014-08-01 10:07
162 查看
转自:http://blog.csdn.net/kdevn/article/details/3862946
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);
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);
相关文章推荐
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Velocity中加载vm文件的三种方式
- Spring加载配置文件的三种方式
- JavaEE细节问题02——加载资源文件的三种方式
- MyBatis总结——加载mappers映射文件的三种方式
- 反射第六步 : 通过反射加载资源文件 三种方式
- java加载文件的三种方式
- velocity中加载模板文件的方式
- MyBatis Review——加载mappers映射文件的三种方式
- Spring的ApplicationContext加载多个配置文件的三种方式
- java加载配置文件的三种方式
- Spring加载配置文件的三种方式
- 加载资源文件的三种方式
- Spring (一) 加载配置文件,实例化类, 三种实例化bean的方式
- JAVA 加载文件的三种方式的区别