org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm" [英] org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm'

查看:36
本文介绍了org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下.

VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "class");
        ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        ve.init();
        Template tempalte = ve.getTemplate("templates/email/test.vm");

我收到以下错误.

org.apache.velocity.exception.ResourceNotFoundException:无法在以下位置找到资源模板/电子邮件/test.vm"org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)在org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)在org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102).....

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm' at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452) at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335) at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102).....

模板"文件夹在我的 src 文件夹中.

"template" folder is in my src folder.

如果我直接把velocity模板文件放到src文件夹下更新为模板 tempalte = ve.getTemplate("test.vm");"它有效.

If I directly put the velocity template file into src folder and update as "Template tempalte = ve.getTemplate("test.vm");" it works.

我使用的是 Mac OS、Java 1.8、Eclipse Neon.

I am using Mac OS, Java 1.8, Eclipse Neon.

请帮我解决这个问题.

谢谢和问候,伊苏鲁J

推荐答案

感谢您抽出宝贵时间.这是一个 ANT 项目.错误地我无法编写脚本来将模板文件夹复制到 WEB-INF/classes 文件夹.这就是问题所在.@user7294900 和 @soorapadman 都是正确的.代码现在可以使用了.

Thanks for your time. This is an ANT project. Mistakenly I couldn't write script to copy templates folder to WEB-INF/classes folder. That was the issue. Both @user7294900 and @soorapadman are correct. The code works now.

非常抱歉给您带来不便.

Really sorry for the inconvenience.

最好的问候,伊苏鲁J

这篇关于org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆