My linux world » Java Spring – Webjars

Java Spring - Webjars


Contents

Prerequistes

Please read : Java spring – quickstart

Configuration

Dependencies

If you use maven, add this to your pom.xml :

<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>webjars-taglib</artifactId>
  <version>0.3</version>
</dependency>
 
<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>jquery</artifactId>
  <version>3.1.1</version>
</dependency>

WebMvcConfig.java

In WebMvcConfig.java, add the ressouce :

@Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/");
}

jsp view

Import the following taglib:

<%@ taglib uri="http://www.webjars.org/tags" prefix="wj"%>

Then locate the file in the webjar :

<script src="<wj:locate path="jquery.min.js" />"></script>

Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub