java org.apache.velocity.exception.ResourceNotFoundException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1317889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:06:51  来源:igfitidea点击:

org.apache.velocity.exception.ResourceNotFoundException

javatemplatesemailvelocity

提问by

I am using velocity engine template for mailing in struts1 and hibernate configuration.

我正在使用速度引擎模板在 struts1 和休眠配置中发送邮件。

I got error: org.apache.velocity.exception.ResourceNotFoundExceptionwhile I try to send mail.

我收到错误:org.apache.velocity.exception.ResourceNotFoundException当我尝试发送邮件时。

I have included velocity1.5.jar, mail.jar, activation.jar, smtp.jar.

我已经包含了velocity1.5.jar、mail.jar、activation.jar、smtp.jar。

I include the velocity template path here

我在这里包含了速度模板路径

String velocityTemplate = "mailTemplate/sendMail.vm";

String velocityTemplate = "mailTemplate/sendMail.vm";

and the mailTemplate folder is in WEB-INF/classesfolder

并且 mailTemplate 文件夹在WEB-INF/classes文件夹中

I got that error when code executes this line

当代码执行这一行时我得到了那个错误

Template template = velocityEngine.getTemplate(velocityTemplate);

Template template = velocityEngine.getTemplate(velocityTemplate);

can any one help me regarding this?

任何人都可以帮助我吗?

It will be more appreciable if any one help me.

如果有人帮助我,那将更加可观。

采纳答案by

As BenM said we have to configure the Resource Loader as a ClasspathResourceLoader

正如 BenM 所说,我们必须将 Resource Loader 配置为 ClasspathResourceLoader

velocityEngine.setProperty("resource.loader", "class");
velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"));

velocityEngine.init();

and I just added the latest version of the following jar. now it's working properly.

我刚刚添加了以下 jar 的最新版本。现在它工作正常。

--> commons-collections-3.2.1.jar

--> commons-collections-3.2.1.jar

--> commons-lang-2.4.jar

--> commons-lang-2.4.jar

once again Thanks BenM

再次感谢 BenM

回答by BenM

Ensure you have called init() on your VelocityEngine.

确保您在 VelocityEngine 上调用了 init()。

Check that you have configured your Resource Loader as a ClasspathResourceLoader. See the Velocity docsfor more info.

检查您是否已将 Resource Loader 配置为 ClasspathResourceLoader。有关更多信息,请参阅Velocity 文档

For the legacy Velocity class you'd do the following:

对于传统的 Velocity 类,您需要执行以下操作:

Velocity.setProperty("resource.loader", "class");
Velocity.init();

回答by Rawheiser

Was struggling with the same issue, finally resolved it.

一直在纠结同样的问题,终于解决了。

  • template file needs to be in the class path.
  • the velocity.properties file doesn't conflict with settings you make prior to init().
  • and that there are not multiple jars of different versions littered around your project.
  • 模板文件需要在类路径中。
  • Velocity.properties 文件与您在 init() 之前所做的设置不冲突。
  • 并且您的项目周围没有散布多个不同版本的罐子。