没有Play插件的Play框架sbt-web集成 [英] Play Framework sbt-web integration without play plugin
问题描述
作为库嵌入游戏,我启用了sbt-web插件我的项目,并已运行web-stage
,使资产逐字复制到target/web/stage/
.但是,使用Play框架的字符串插值路由DSL 时,当匹配请求来自:
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.
那么sbt-web管理将资产放置在那里的缺失是什么?当手动放置在那里时,集成有效!!因此似乎sbt-web在其默认配置下,就Play而言,将资产放置在错误的目标子目录中...
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...
请注意,在plugins.sbt
中,我仅包含sbt-web中的以下内容,这够吗?
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")
推荐答案
将资产放置在/src/main/resources/assets/
下,可以在运行时将其复制到target
,从而绕过任何奇特的sbt-web处理.这使您摆脱了基本开发的泥潭.
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.
路线需要像这样修改:
case GET(p"/public/$file*") => {
val path = "/assets"
Assets.at(path = path, file = file)
}
设置适当的sbt-web管道以进行最小化或最终无法避免的事情,因此,这并不是真正的答案,但是它可以解决内部使用的应用程序的某些用例.
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.
这篇关于没有Play插件的Play框架sbt-web集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!