O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Integrating Bootstrap and WebJars

For this recipe, we will explore how we can integrate and utilize the popular frontend framework Bootstrap with a Play 2 web application. We will integrate Bootstrap using WebJars, which is a tool to package frontend libraries into JAR files that can then be easily managed (in our case, by sbt).

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator "~run"
    
  2. Declare Bootstrap and WebJars as a project dependency in build.sbt:
        "org.webjars" % "bootstrap" % "3.3.1",
        "org.webjars" %% "webjars-play" % "2.3.0"
  3. Modify foo_java/app/controllers/Application.java by adding the following code:
     public static Result bootstrapped() { return ok(views.html.bootstrapped.render()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required