Coming Up for Air

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:

build.gradle
1
2
3
4
5
dependencies {
    // ...
    compile 'org.webjars:bootstrap:3.0.0'
    // ...
}
pom.xml
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:

index.xhtml
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.

Search

    Quotes

    Sample quote

    Quote source

    About

    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links

    Publications