Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webjars In Spring Boot - Javascript not loading

I am trying to add jQuery to my Boot app using Webjars. I got the inspiration from this tutorial: http://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot

In my pom.xml I have added:

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.1</version>
</dependency>

In my html file (using ThymeLeaf for my template engine - not sure if this matters) I have the following:

<script src="webjars/jquery/2.1.1/jquery.min.js"></script>

The file does not load. I have tried both src="webjars...." and src="/webjars...".

I can see the jar in the Maven dependancies listed in my project. When I explore this jar I can see META-INF/resources/webjars/jquery/2.1.1/jquery.min.js. Based on how I understand Boot looks for resources, I think it should find this.

Anyone see this sort of behavior? Any tips on how to trouble shoot it?

like image 772
user2188484 Avatar asked Sep 18 '14 17:09

user2188484


1 Answers

This works for me:

<script src="/webjars/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>

Are you sure it's actually on the classpath at runtime? Are you running an app with a context path (i.e. not serving assets from "/")?

like image 125
Dave Syer Avatar answered Oct 14 '22 20:10

Dave Syer