Re: Loading templates from classpath ( ClassTemplateLoader problem or /dev/hands ? )
akuntamukkala <[email protected]> Thu, 21 Feb 2013 10:32:01 -0800 (PST)
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Here is what I did to get around this problem with ClassTemplateLoader
The issue is that the proper class loader isn't being used. I got around
this by subclassing ClassTemplateLoader
public class FixedClassTemplateLoader extends ClassTemplateLoader {
private ClassLoader classLoader;
public FixedClassTemplateLoader(Class clazz, String string) {
super(clazz, string);
classLoader = clazz.getClassLoader();
}
@Override
protected URL getURL(String name) {
// this now loads the template file from the jar
return classLoader.getResource(name);
}
}
then here is how I used it
ClassTemplateLoader ctl = new FixedClassTemplateLoader(getClass(),
"templates");
TemplateLoader[] loaders = new TemplateLoader[] { ctl };
MultiTemplateLoader mtl = new MultiTemplateLoader(loaders);
cfg.setTemplateLoader(mtl);
Template template = cfg.getTemplate("templates/testEmailTemplate.ftl");
----
Now I am able to load the template and generate my email template.
Thanks
--
View this message in context: http://freemarker.624813.n4.nabble.com/Loading-templates-from-classpath-ClassTemplateLoader-problem-or-dev-hands-tp625098p4654453.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb