Introduction to Spring Boot WebJars

1. Introduction

Among the other features that Spring Boot simplifies, one of them is the webjars. Webjars are the static client-side dependencies (for eg. javascript libraries) packaged into JARs. Manually adding the client side libraries could be difficult to maintain, so with webjars (feature enhanced in Spring Boot), we can add these libraries just by making required pom configuration entries, and we are all-set to start using them instantly.

Webjars works with commonly used build tools like Maven and Gradle and makes it very easy to manage and maintain.

2. How it works?

This means that just with the below specification in pom.xml file, the Bootstrap and jQuery becomes ready for us to use it in our HTML page or any of the view technology we are using.

We can now directly use the client-side libraries in our view pages like –

Spring Boot automatically configures Spring to map requests for /webjars to the /META-INF/resources/webjars directory of all the JARs in the CLASSPATH.

Things can also work out even without specifying the WebJar (client-side library) versions while including them in HTML view files, like we mentioned in the previous snippet. For this to work, we need to additionally insert the below mentioned webjar-locator dependency into the pom file.

Spring Boot automatically detects the webjars-locator library in the classpath and uses it to automatically resolve the version of WebJars we are trying to insert into our HTML page.

Reference Link

3. Download the source code

We have very good working example ready for you. Please click on the below GitHub link to download.

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.