JPragma Blog

Pragmatic Developers, Elegant Software

Static content and webjars in Micronaut applications

leave a comment »

Sometimes I need to add a very simple UI to my Micronaut applications. Lightweight javascript libraries such as JQuery or AngularJS are quite convenient for this purpose. Traditionally CDNs are used to reference and download these libraries at runtime, but I prefer to use webjars. This way my app will continue to work even if there is no internet connection or if certain CDN is blocked by e.g. corporate network policies.

Step 1

Add dependency to the webjar. In gradle this would look like:


Step 2

Add following configuration to application.yml

    name: myapp
          - "classpath:public"
          - "classpath:META-INF/resources/webjars"

Step 3

Create static resources (html, js, css) under src/main/resources/public

Step 4

Reference webjar javascript library from html

    <script src="jquery/3.5.1/jquery.min.js"></script>

Written by isaaclevin

February 28, 2021 at 4:39 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: