Adding Static Paths in Bootique

If you're using Bootique Jetty, MVC or another web-based Bootique module you'll probably want to add a static path to your /css and other resource directories. In this short post we'll do just that. You can find the code in the NixMash Microservices Web Client module.

We want to retrieve CSS and other resources in our .html pages with something like this, with no "/static" in the file path.

<link href="/css/application.css" rel="stylesheet">

Static Servlet

In our Bootique Module configure() logic we're going to add a Static Servlet. The name is "s1" and can be anything if you're not referencing it in the bootique.yml or elsewhere. Then we add the static paths which are below our /static root directory.


I mentioned the bootique.yml earlier in regards to referencing the name of the Static Servlet. We could actually add directories directly in the bootique.yml. I had issues doing that. The Bootique Jetty Documentation on the topic is really good if you're smarter than me and want to go with an all-bootique.yml approach.

If you add the Static Servlet in the Jetty Module like I did above, then you'll define the staticResourceBase like so, and you're done.

Source Code Notes for this Post

Source code discussed in this post is found in NixMash Microservices on GitHub. Code for this particular post is found in branch microservices-v0.1.0 – Initial Layout and Structure.