Skip to content
An example Dropwizard application indicating how to include View templates from sources outside the main jar file.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Documentation, example config file. Apr 27, 2016
src Javadoc tweaks. Apr 27, 2016
.gitignore Initial commit Apr 12, 2016 Add blog post link to README. Apr 27, 2016
pom.xml Implement mustache multi-location view. Apr 26, 2016

Dropwizard external views - example project

This project illustrates how to add external templates to a Dropwizard application, allowing you, for example, to have dynamic templates for an evolving set of document types.

It came about after we revisited a client who needed to do exactly that. They were using Dropwizard 0.6.2, and it was unexpectedly difficult to make changes to templates, or to add new templates to the project. I decided to investigate how difficult it would be to do the same thing in a more recent version of Dropwizard - 0.9.2. Read the full story here.

Updated and extended classes

  • MultiLocationViewBundle - this is a drop-in replacement for the default Dropwizard ViewBundle. It relies on...
  • MultiLocationViewConfiguration - this extends the default Dropwizard Configuration class, adding a views element with details of the template locations.
  • ViewsConfiguration - a configuration class representing the content of the views element held in the MultiLocationViewConfiguration.
  • MultiLocationViewRenderer - an extension to the Dropwizard ViewRenderer interface, adding a configureLocations() method.
  • multiple location variants of the view renderers for both Freemarker and Mustache templates. There is quite a lot of duplicated code here, unfortunately.


The view configuration should look like that given in the config/example.yml file:

# Additional configuration for the external views.

    - /data/templates/freemarker
    - /data/templates/mustache
    - classpath

      # Freemarker configuration

The templatePaths element holds an array of paths to be used to search for templates. Note that the special classpath reference, which indicates that the jar file should be included in the list of search locations, is not assumed or implied, and needs to be explicitly specified. If templatePaths is not given, the jar file will be used as normal.

The renderers element contains the renderer-specific configuration, and will be passed to the appropriate Renderer implementation as mentioned in the Dropwizard Views documentation.

You can’t perform that action at this time.