Setting freemarker template from classpath

Posted by wuntee on Stack Overflow See other posts from Stack Overflow or by wuntee
Published on 2010-06-11T00:10:45Z Indexed on 2010/06/11 0:12 UTC
Read the original article Hit count: 663

Filed under:

I have a web application that I need to manually obtain a Freemarker template - the template is obtained via a class in a library project, but the actual tpl file is contained in the web application classpath. So, there are 2 projects, one 'taac-backend-api' and another 'taac-web'; taac-backend-api has the code to grab the template, and process it, but taac-web is where the template is stores (specifically in: WEB-INF/classes/email/vendor.tpl) - I have tried everything from using springs classpath resource to using Freemarkers setClassForTemplateLoading method. I assume this would work:

    freemarkerConfiguration = new Configuration();
    freemarkerConfiguration.setClassForTemplateLoading(this.getClass(), "");
    Template freemarkerTemplate = freemarkerConfiguration.getTemplate("/email/vendor.tpl");

yet, I always get a FileNotFoundException. Can someone explain the best way to obtain a template from the classpath?

Thanks.

© Stack Overflow or respective owner

Related posts about freemarker