I am trying to create a simple jersey-freemarker webapp, which I'm running with the jetty-maven-plugin.
But the FreemarkerViewProcessor
won't find my templates.
I have created a jersey resource at @Path("/")
with a @GET public Viewable getIndex()
method, that gets invoked once I request http://localhost:8080/
.
This Viewable
is set to use the "index"
template.
Assume the resource is com.example.MainResource
(located in src/main/java/com/example/MainResource.java
), and the index.ftl
template file is located in src/main/webapp/templates/com/example/MainResource/index.ftl
.
In my servlet setup, I tell jersey-freemarker about the templates
directory, using a configuration Map
: config.put(FreemarkerViewProcessor.FREEMARKER_TEMPLATES_BASE_PATH, "templates");
.
When debugging the FreemarkerViewProcessor
, I see that it is indeed looking for the template resource based on the path /templates/com/example/MainResource/index.ftl
.
Where should I put my template files so the FreemarkerViewProcessor
will find them? Or how do I include my templates
directory in the classpath?
PS: mvn jetty:run
produces the following output (in part):
[INFO] Configuring Jetty for project: jettytest-servlet
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = ~/jettytest-servlet/target/classes
[INFO] Context path = /
[INFO] Tmp directory = ~/jettytest-servlet/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:~/jettytest-servlet/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = ~/jettytest-servlet/src/main/webapp
Update:
The FreemarkerViewProcessor
always uses a default Configuration
, which sais to use a class-loader based template loader.
As per @ddekany's comment, I should therefore place my templates/
in WEB-INF/classes/
. To me that feels dirty; it seems like this should be taken care of by Maven.
Because of the FreemarkerViewProcessor
's design (always using a class-loader configuration), I have posted this follow-up question. In the meantime, suggestions telling me how I can add the src/main/webapp/
directory to the classpath are welcome as well.