`

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

阅读更多

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

 

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

 

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


开始是天真的放在同一目录下的相对路径,结果一次又一次的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"

 


放在这个目录就没事了。

 

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

 

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

 

  • 大小: 32.9 KB
  • 大小: 11.5 KB
分享到:
评论
1 楼 zgdnba 2012-07-02  
really helpful

相关推荐

Global site tag (gtag.js) - Google Analytics