问题
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