WebJars and JSF
Wednesday, August 28, 2013 |WebJars, for those that haven’t heard, is a project that takes popular client-side web libraries and packages them in JARs to make their use in Java-/JVM-based web apps simpler. The web site notes that you can easily see which libraries a project is using simply by looking at its dependencies, and that transitive dependencies automatically appear. It’s a pretty compelling project, but, for some reason, it doesn’t show how to integrate it with JSF. I’d like to think it’s because it’s so trivial, but I’ll show it here anyway. :)
The first step is to add it to your build. We’ll use Bootstrap 3.0 in our example:
1
2
3
4
5
dependencies {
// ...
compile 'org.webjars:bootstrap:3.0.0'
// ...
}
1
2
3
4
5
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.0.0</version>
</dependency>
The next step is adding it to the page:
1
2
3
4
5
6
<h:head>
<h:outputStylesheet library="webjars/bootstrap/3.0.0/css"
name="bootstrap.min.css"/>
<h:outputScript library="webjars/bootstrap/3.0.0/js"
name="bootstrap.min.js"/>
</h:head>
That’s it. Build and deploy your app, and Bootstrap (or the library of your choice) is ready to use.