Play Framework sbt-web integration without play plugin

家住魔仙堡 提交于 2019-12-13 06:12:36

问题


Embedding play as a library, I enabled the sbt-web plugin in my project, and have run web-stage, making assets copied verbatim to target/web/stage/. However using Play Framework's string interpolation routing DSL as follows, they are not served when a matching request comes in:

object PlayServer extends App {
    val server = NettyServer.fromRouter() {   
      case GET(p"/public/$file*") => {
        val path = "/target/web/stage"
        Assets.at(path = path, file = file)
    }
}

Debugging through the play code handling Assets.at, it looks like nothing brings the assets into being resources under target/scala-2.11/classes/, where presumably play framework is trying to load them as resources from. Running sbt web-stage does not take care of specifically that.

So what is missing for sbt-web managing to take care of placing the assets there? When manually placed there, the integration works!! so it seems sbt-web in its default configuration places the assets in the wrong target subdirectory as far as Play is concerned...

Please note that in plugins.sbt I include only the following from sbt-web, should that be enough?

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "latest.release")

回答1:


Placing the assets under /src/main/resources/assets/ gets them copied to target upon running, bypassing any fancy sbt-web processing. This gets you out of the mud for basic dev.

The route needs to adapted like so:

case GET(p"/public/$file*") => {
  val path = "/assets"
  Assets.at(path = path, file = file)
}

Setting up a proper sbt-web pipeline for minification or whatever cannot ultimately be avoided, hence this is not really an answer, but it solves a certain use case using play for internally used applications.



来源:https://stackoverflow.com/questions/36487410/play-framework-sbt-web-integration-without-play-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!