Web Jars is a dependency management technique which reduces the leraning curve of the developer to use single dependency management system to manage the versions of JavaScript libraries or other non-maven-standard libraries which has other then java code
For Example: i you want to add jQuery into your spring boot project, in the past you need to put that in the static folder manually of you need to use tools like bower to download it inside the static folder
but now you don't have to do that, you can use same pom.xml or build.gradle and specify the webjar dependency
Gradle Example
compile group: 'org.webjars', name: 'jquery', version: '3.4.1'
Maven Example
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
then in your spring boot project you have to add a URL mapping common to all webjars as below
@Configuration
@EnableWebMvc
class WebConfig: WebMvcConfigurer {
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.resourceChain(true)
}
}
then to use this in your HTML code you need the below code
<script src="/webjars/jquery/jquery.min.js"></script>
this reduces the manual download of javascript and allows you to maintain due-diligence in your build system