I am using Apache Velocity template engine for my web application html email utility.
But the major problem i am facing is the resource path.
I am using struts2 for my web application(Struts2 maven arch.. project)
& i have created folder templates & inside of it i have created email.vm file which is template so i moved templates folder to resource (So when war will be created it will go to WEB-INF/classes folder)
& in my utility class i am trying to get the template as follow:
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put("petList", list);
log.info("Context added");
/*
* get the Template
*/
Template t = ve.getTemplate("email.vm" );
log.info("Got Template");
/*
* now render the template into a Writer, here
* a StringWriter
*/
StringWriter writer = new StringWriter();
t.merge( context, writer );
So i am getting error
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource ‘template.vm’
I gone through every related question on this in stackoverflow & applied the solution but still no luck
So can somebody tell me whats wrong i am doing or missing ??
Read this http://velocity.apache.org/engine/releases/velocity-1.5/developer-guide.html#resourceloaders and this http://tech–help.blogspot.com/2010/02/solved-apache-velocity-how-to-load.html. And use google next time.