1
votes

Hi I try to integrate play framework (current) 2.3.7 with Bootstrap 3:

sbt file:

libraryDependencies ++= Seq(
  "org.webjars" %% "webjars-play" % "2.3.0-2",
  "org.webjars" % "bootstrap" % "3.1.1-2"
)

html

<body>
    

            <!-- Latest compiled and minified CSS -->
  
        <link rel='stylesheet' href='@routes.Assets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>

      

        <ul class="nav nav-tabs">
            <li role="presentation" class="active"><a href="#">Home</a></li>
            <li role="presentation"><a href="#">Profile</a></li>
            <li role="presentation"><a href="#">Messages</a></li>
        </ul>

Only throws this error: [MultipleMatchesException: Multiple matches found for css/bootstrap.min.css. Please provide a more specific path, for example by including a version number.]

a different try (which should have worked on earlier 2.3 versions): http://www.webjars.org/documentation

<link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))'></script>

But Play only tells me that the web jar assets controller is not available

value WebJarAssets is not a member of object controllers.routes
can someone tell me what is wrong?
3
this seems to work --> but does not seem correct? --> what is the right / best approach? <link rel='stylesheet' href='@routes.Assets.at("/lib/bootstrap/css/bootstrap.css")'> I try to get something like: github.com/knoldus/playing-reactive-mongo/blob/master/app/views/… but: <link rel="stylesheet" media="screen" href="@routes.WebJarAssets.at(WebJarAssets.locate("bootswatch-united", "bootstrap.min.css"))"> does not work --> as stated in the question. - Georg Heiler
Why did you use code snippets everywhere? They are of no use here and clutter the post. - BAR

3 Answers

3
votes

Do you have an entry in your routes file for the WebJarAssets controller? Something like this:

GET     /webjars/*file                    controllers.WebJarAssets.at(file)
2
votes

In my case I got the error:

value WebJarAssets is not a member of object controllers.routes

even though I had added

GET     /webjars/*file     controllers.WebJarAssets.at(file)

to the routes file.

sbt clean did not help. I ended up with git clean -f -d -x which removes everything not tracked by git. Then it compiled.

1
votes

You simply use the Assets controller to access WebJars, they are extracted by Play automatically to the target/lib folder. You can refer to them via @routes.Assets.at(“lib/bootstrap/css/bootstrap.css”).