简体   繁体   中英

org.apache.velocity.exception.ResourceNotFoundException

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.

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

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM