views:

1072

answers:

3

Hi All,

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 regards.

Thank you in anticipation

Syed Shahul

+1  A: 

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();
BenM
could you please tell me where should that Resource Loader to be configured
do we need to configure any thing in web.xml ?but i am using velocity only for mail
I've updated to show how to configure the class resource loader.
BenM
thank you Ben,i have added that lines in my code but till the problem persist!.
A: 

Hi All,

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 add the latest version of the following jar. now its working properly.

--> commons-collections-3.2.1.jar

--> commons-lang-2.4.jar

once again Thanks BenM

A: 

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.
Rawheiser