首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

velocity学习-第一个例证就错,Unable to find resource

2012-09-08 
velocity学习-第一个例子就错,Unable to find resource本人还是菜鸟,希望各位大虾指教!!?刚开始学习veloci

velocity学习-第一个例子就错,Unable to find resource

本人还是菜鸟,希望各位大虾指教!!

?

刚开始学习velocity就报错org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource ,死活解决不了,最后看了下源码,终于找到错误所在了

?

从官网copy自己稍微改下的例子


velocity学习-第一个例证就错,Unable to find resource

开始是天真的放在同一目录下的相对路径,结果一次又一次的Unable to find resource

?

最后实在受不了,追踪了下velocity的源码

在org.apache.velocity.runtime.resource.loader.FileResourceLoader

  public boolean resourceExists(String name)    {        if (name == null)        {            return false;        }        name = StringUtils.normalizePath(name);        if (name == null || name.length() == 0)        {            return false;        }        int size = paths.size();        for (int i = 0; i < size; i++)        {            String path = (String)paths.get(i);            try            {                File file = getFile(path, name);                if (file.canRead())                {                    return true;                }            }            catch (Exception ioe)            {                String msg = "Exception while checking for template " + name;                log.debug(msg, ioe);            }        }        return false;    }
?

最后是变成了"./Test1.vm"

?


velocity学习-第一个例证就错,Unable to find resource

放在这个目录就没事了。

?

“.”代表的应该是项目的根路径

?

最后试了下使用“/Test.vm”,“./Test.vm”和“Test.vm”一样

?

热点排行