Static content and webjars in Micronaut applications
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 a certain CDN is blocked e.g. by corporate network policies.
Step 1
Add dependency to the webjar. In gradle this would look like:
Step 2
Add following configuration to application.yml
Step 3
Create static resources (html, js, css) under src/main/resources/public
Step 4
Reference webjar javascript library from html
Written on February 28, 2021