感谢xsbt-scalate-precompile-plugin的作者 Keith Irwin,我现在有了解决问题的方法。
我的 Jade/Scalate 文件位于 webapp/WEB-INF/template 和 webapp/WEB-INF/scalate/layouts 目录中。
我正在使用 xsbt-web-plugin 和 xsbt-scalate-precompile-plugin sbt 插件。
- xsbt-web-plugin 为我提供了 package-war 命令。
- xsbt-scalate-precompile-plugin 预编译我的 Jade 文件。
在我的 plugins.sbt 文件中。
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
addSbtPlugin("com.github.siasia" %% "xsbt-web-plugin" % "0.1.2")
resolvers += "zentrope" at "http://zentrope.com/maven"
addSbtPlugin("com.zentrope" %% "xsbt-scalate-precompile-plugin" % "1.7")
在我的 build.scala 文件中。
import WebPlugin._
import Keys._
import com.zentrope.ScalatePlugin._
...
// WebApp Settings
val webAppSettings = Seq(
jettyPort := 8083,
jettyContext := "/MyWebApp"
)
// Scalate Compile Settings
val scalateCompileSettings = scalateTemplateSettings ++ Seq(
scalateTemplateDirectories in Compile <<= (scalateTemplateDirectories in Compile, baseDirectory) {
(dirs, basedir) => dirs ++ Seq(new File(basedir, "/src/main/webapp/WEB-INF/template"),
new File(basedir, "/src/main/webapp/WEB-INF/scalate/layouts"))
}
)
...
lazy val MyWebApp =
Project("MyWebApp", file("MyWebApp"), settings = shared ++ webAppSettings ++ scalateCompileSettings ++ Seq(
resolvers ++= Seq(sonatypeNexusReleases, scalaToolsNexus, novusRels, scalaToolsSnapshots),
libraryDependencies ++= Seq(
scalatra,
scalate,
...
)
))
The 1.7 version of Keiths' plugin allows for the setting of specific template directories which is what I really needed. The only caveat is that I must do a clean right before I call package-war or my compiled Jade files get removed.