perwendel / spark-template-engines

Repository for different Template engine implementations.
Apache License 2.0
134 stars 101 forks source link

FreeMarker Template load location missing #58

Open edigitman opened 7 years ago

edigitman commented 7 years ago

I have a POC with the following dependencies com.sparkjava spark-core 2.5 com.sparkjava spark-template-freemarker 2.5.5

I took the example from this repo, the FreeMarkerEngine class. I have the simple Main class and a simple template with a placeholder for the message.

The issue is that in the Main class there is a comment saying that the template will be loaded from src/test/resources/spark/template/freemarker but this is not configured in the FreeMarkerEngine class at line 89 configuration.setClassForTemplateLoading(FreeMarkerEngine.class, "");

The second argument should be "spark\template\freemarker".

Dobosz commented 7 years ago

This line is exactly like it supposed to be. This empty string is base package for getResource() of selected class loader. In this case FreeMarker will execute something like: FreeMarkerEngine.class.getClassLoader().getResource (basePackage + ...)

If you are looking for path for template files see: http://freemarker.org/docs/api/freemarker/template/Configuration.html#setDirectoryForTemplateLoading-java.io.File-