org.apache.velocity.exception.ResourceNotFoundException

孤街醉人 提交于 2019-12-08 18:46:45

问题


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

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

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

I include the velocity template path here

String velocityTemplate = "mailTemplate/sendMail.vm";

and the mailTemplate folder is in WEB-INF/classes folder

I got that error when code executes this line

Template template = velocityEngine.getTemplate(velocityTemplate);

can any one help me regarding this?

It will be more appreciable if any one help me.


回答1:


As BenM said we have to configure the Resource Loader as a 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.

--> commons-collections-3.2.1.jar

--> commons-lang-2.4.jar

once again Thanks BenM




回答2:


Ensure you have called init() on your VelocityEngine.

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

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

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



回答3:


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.


来源:https://stackoverflow.com/questions/1317889/org-apache-velocity-exception-resourcenotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!