webjars / webjars-play

MIT License
80 stars 34 forks source link

webjars-play not working java project #89

Closed EdozdeDandez closed 5 years ago

EdozdeDandez commented 5 years ago

Hi I'm having a problem using webjars-play on a newly created play JAVA project 2.7.3. I have changed the routes and the build.sbt files as required and downloaded it but incorporating it in the view files is a problem if I put the line at the very top of the main.scala.html page as follows: ` @this(webJarUtil: org.webjars.play.WebJarsUtil) @*

_ not found: value main ` @main("Welcome to Play") {

Welcome to Play!

} _ If I move the webJarUtil line down as follows: @(title: String)(content: Html) @this(webJarUtil: org.webjars.play.WebJarsUtil) <!DOCTYPE html>

@* Here's where we render the page title `String`. *@ @title @webJarUtil.locate("bootstrap.min.css").css() @* And here's where we render the `Html` object containing * the page content. *@ @content @webJarUtil.locate("jquery.min.js").script() @webJarUtil.locate("bootstrap.min.js").script() @webJarUtil.requireJs(routes.Assets.versioned("javascripts/index.js"))

` I get the error:

not found: value webJarUtil @this(webJarUtil: org.webjars.play.WebJarsUtil) `

build.sbt

name := """my-first-play-project""" organization := "com.example" version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayJava) scalaVersion := "2.13.0" libraryDependencies += guice libraryDependencies ++= Seq( "org.webjars" %% "webjars-play" % "2.7.3", "org.webjars" % "bootstrap" % "4.3.1" exclude("org.webjars", "jquery"), "org.webjars" % "jquery" % "3.4.1", "org.webjars" % "jquery-ui" % "1.12.1", "org.webjars" % "font-awesome" % "5.9.0", )

routes

`

Routes

This file defines all application routes (Higher priority routes first)

~~~~

An example controller showing a sample home page

GET / controllers.HomeController.index

My pages

Map static resources from the /public folder to the /assets URL path

GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

WebJars

-> /webjars webjars.Routes `

What am I doing wrong?

jamesward commented 5 years ago

I'm having a hard time following what is going on due to formatting. Did you restart the build after updating the build.sbt file?

EdozdeDandez commented 5 years ago

Yes I restarted it.

EdozdeDandez commented 5 years ago
  1. bild.sbt Screen Shot 2019-08-06 at 21 14 33

  2. main.scala.html with webjarutil declaration at the top Screen Shot 2019-08-06 at 21 14 12

  3. main.scala.html with webjarutil declaration just before the doctype Screen Shot 2019-08-06 at 21 13 48

  4. routes Screen Shot 2019-08-06 at 21 13 07

  5. index.scala.html Screen Shot 2019-08-06 at 21 19 07

Putting the declaration at the top of the main.scala.html gives the error- not found: value main Putting the declaration just before the doctype of the main.scala.html gives the error- not found: value webJarUtil

EdozdeDandez commented 5 years ago

I hope it's clear now

jamesward commented 5 years ago

Oh! I see. The problem is that if you do injection into a template, then to use that template you must inject it, so in index.scala.html do:

@this(webJarsUtil: org.webjars.play.WebJarsUtil, main: main)

For reference see: https://github.com/webjars/webjars/blob/master/app/views/index.scala.html

EdozdeDandez commented 5 years ago

Thanks a lot. Will try that