---
title: "Struts2采用velocity作为view后，增加新的vm模板查找路径"
author: "NetBus"
date: "2010-05-27T15:55:04Z"
tags: []
categories: ["企业架构"]
slug: "struts2-velocity-view-vm"
draft: false
lastmod: "2010-05-27T15:55:04Z"
id: 676942
url: "https://netbus.iteye.com/blog/676942"
---

作为记号，怕搞忘：

 

struts2的velocity引擎一般会以web根路径作为vm默认查找路径。如：#parse("/xx.vm")，则会到实际运行的web根目录下查找该文件。如果想增加外面的vm模板引用，则必须要更改velocity配置文件。

 

在velocity.peroperties中增加选项：

- resource.loader=strutsfile, strutsclass, file
- file.resource.loader.path=/home/vm

其中，resource.loader表示定义了velocity资源装载的方式。struts2中默认为strutsfile和strutsclass，需要增加：file

并且还要增加查找地址：file.resource.loader.path，这个选项指定了.vm文件存放地址。

这样配置后，velocity模板引擎会按照定义的先后顺序查找.vm文件。