Reputation: 293
I was using this tutorial to learn FreeMarker but it seems deprecated. I added
Configuration cfg = new Configuration(Configuration.VERSION_2_3_30);
for the Configuration object, but then I get the following exception:
freemarker.template.TemplateNotFoundException: Don't know where to load template "C:\\test\\helloworld.ftl" from because the "template_loader" FreeMarker setting wasn't set (Configuration.setTemplateLoader), so it's null
How to set up the TemplateLoader correctly in this tutorial example?
Upvotes: 0
Views: 2411
Reputation: 31
the same thing happened to me but I found this on the internet, we have to load the folder that we use within "resources"
final Configuration freeMarCfg = new Configuration(Configuration.VERSION_2_3_30);
final ClassTemplateLoader loader = new ClassTemplateLoader(Main3.class, "/templates");
freeMarCfg.setTemplateLoader(loader);
freeMarCfg.setDefaultEncoding("UTF-8");
freeMarCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
final String fileTemplate = "getPositions.ftl";
final Template weatherByCityTmplate = freeMarCfg.getTemplate(fileTemplate);
i saw it on this site: https://www.concretepage.com/freemarker/freemarker-configuration-with-classtemplateloader-example
Upvotes: 3