Documentation

WebJars work with most JVM-based containers and web frameworks.

Using a WebJar requires:

  1. The WebJar needs to be a dependency of your application
  2. The WebJar needs to be in your application's running CLASSPATH
  3. Your container, web framework, or application needs to serve static assets from Jar files

Public CDN via jsDelivr

All of the WebJar contents are available on the public jsDelivr CDN. Just prefix //cdn.jsdelivr.net/webjars/{groupId} in front of your static asset URLs. For instance, if using the org.webjars : jquery WebJar and your local URL to jquery.js is /webjars/jquery/2.1.0/jquery.js then the CDN URL would be: //cdn.jsdelivr.net/webjars/org.webjars/jquery/2.1.0/jquery.js

Instructions for Play 2.6 (Sample Source)

WebJars can be added as dependencies to an app by simply adding them to the build.sbt file like:

libraryDependencies += "org.webjars" % "bootstrap" % "3.1.1-2"

Play automatically extracts the WebJar contents and makes them available via the Assets controller.

Instructions for Xitrum

Xitrum can serve static files from classpath, which includes WebJars. See Xitrum documentation.

Instructions for Servlet 3

With any Servlet 3 compatible container, the WebJars that are in the WEB-INF/lib directory are automatically made available as static resources. This works because anything in a META-INF/resources directory in a JAR in WEB-INF/lib is automatically exposed as a static resource.

Maven Example (example app)

First add a WebJar as a dependency of your application in the pom.xml file, like:

<dependencies>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

Then simply reference the resource like:

<link rel='stylesheet' href='webjars/bootstrap/3.1.0/css/bootstrap.min.css'>

Instructions for Servlet 2

WebjarsServlet allows Webjars resources to be referenced in legacy apps that are still running on Servlet containers that are not compliant with the Servlet 3 specification.

Usage

Register the webjars-servlet-2.x Maven dependency and WebjarsServlet in your web.xml.

Instructions for JSF

With JSF, the WebJars that are in the WEB-INF/lib directory are automatically made available as resource libraries. This works because WebJars are compatible with the JSF resource identifier format.

Maven Example (example app)

First add a WebJar as a dependency, then reference the resource like:

<h:outputStylesheet library="webjars" name="bootstrap/3.1.0/css/bootstrap.min-jsf.css" />

Instructions for Grails (example app)

Grails manages static resources with the resources plugin. The Grails Modules Manager plugin allows dependencies on web libraries to be declared in the Grails build configuration file.

Instructions for Dropwizard (example app)

With Dropwizard you can easily expose WebJars through the AssetsBundle.

addBundle(new AssetsBundle("/META-INF/resources/webjars", 0, "/webjars"));

Now you can reference a WebJar asset like:

<link rel='stylesheet' href='/webjars/bootstrap/3.1.0/css/bootstrap.min.css'>

Instructions for Spring Boot (example app)

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

Maven Example

First add a WebJar as a dependency, then reference a WebJar asset like:

<link rel='stylesheet' href='/webjars/bootstrap/3.1.0/css/bootstrap.min.css'>

Instructions for Spring MVC

Spring MVC makes it easy to expose static assets in JAR files using ResourceHandlers.

Maven Example (example app)

Configure Spring to map requests for /webjars to the /META-INF/resources/webjars directory.

Instructions for Apache Tapestry (example app)

Apache Tapestry makes it easy to expose static assets in JAR files using contributeClasspathAssetAliasManager.

Instructions for Apache Wicket (example app)

The Wicket integration of Webjars uses a special IResourceFinder implementation to map Webjars resources.

Instructions for Pippo

The Pippo integration of Webjars is pretty straightforward.

Instructions for Ring (example app)

Ring makes it easy to expose WebJars through the wrap-resource function.

Instructions for Dandelion

Dandelion provides a WebJars integration via a dedicated locator for WebJars.

Instructions for Vert.x Web

The Vert.x Web StaticHandler can resolve file paths from both the filesystem and the classpath.

Instructions for Quarkus

Quarkus support the use of WebJars by default and also adds a WebJar Locator to reference WebJars without the version.

Instructions for Ktor (Sample Source)

Add the webjars-locator-lite dependency and your WebJars, then define a routing path with the locator.