java - Spark Framework and relative path -
i'm using spark framework create web app , i've been going through tutorials on site. @ moment, i'm working on templates section, can't seem project recognize css , templates in resources folder.
i'm using netbeans , maven manage dependencies.
can me figure out how set relative paths/create project folders appropriately in environment? i'm newbie both maven , spark, go easy please.
static files:
if resources directory looked this:
resources └───public ├───css │ style.css ├───html │ hello.html └───templates template.ftl
you use staticfiles.location("/public")
. make /public
root staticfiles directory.
you access hello.html
this: http://{host}:{port}/html/hello.html
if wanted use external location on filesystem, use staticfiles.externallocation(...)
, works pretty same way above.
note:
staticfiles.externallocation(...)
can set project's resources directory, means files automatically refreshed (useful development)
a more in depth explanation can found in the spark documentation
configuring template engine:
if have set staticfiles location, spark still having trouble finding templates, try this.
note: these examples freemarker engine, though should apply other engines minor tweaking.
after looking through examples, seems default, new freemarkerengine()
looks templates in spark/template/freemarker
, , not staticfiles location.
you have 2 options:
1: move of templates directory
or
2: configure own engine, , pass instead when defining routes
freemarkerengine freemarker = new freemarkerengine(); configuration config = new configuration(); config.settemplateloader( new classtemplateloader(your_class.class, "/templatedir")); freemarker.setconfiguration(config);
Comments
Post a Comment