我有一个包含两个模块的多模块 Play Framework 项目,common
这是一个包含可重用代码和资产的标准项目,app
也是我要运行的 play 项目。使用 Sbt-Web 插件,我可以创建和修改每次重新加载应用程序时common/src/main/public
复制到文件夹中的资产。app/target/web/web-modules/main/webjars/lib/common
我的问题是在我的 Play 视图中引用这些资产。我的routes
文件包含以下行
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /webjars/*file controllers.WebJarAssets.at(file)
我正在尝试通过例如访问我的index.scala.html
文件中的这些导出资产app
<link rel="stylesheet" media="screen" href="@routes.WebJarAssets.at(WebJarAssets.locate("common/css/directives.css"))">
该文件确实存在app/target/web/web-modules/main/webjars/lib/common/css/directives.css
但WebJarAssts.locate
返回
{"status":{"errors":[{"message":"common/css/directives.css could not be found. Make sure you've added the corresponding WebJar and please check for typos."}]}}
我已经尝试指定更多和更少的路径,并通过 将其作为标准资产进行访问Assets.at
,但没有运气。有谁知道如何正确引用导出的资产?
build.sbt
我文件中的相关行是
val playVersion = play.core.PlayVersion.current
lazy val common = project.enablePlugins(SbtWeb, SbtTwirl).settings(
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % playVersion % "provided",
)
)
lazy val app = project.enablePlugins(PlayJava).settings(
libraryDependencies ++= Seq(
"org.webjars" %% "webjars-play" % "2.3.0"
)
).dependsOn(common % "compile->compile;test->test")
lazy val suite = project.in(file(".")).aggregate(common, app)