4

我正在尝试基于 scalatra-sbt.g8 的以下内容:

class FooWeb extends ScalatraServlet with ScalateSupport {
  beforeAll { contentType = "text/html" }
  get("/") {
    templateEngine.layout("/WEB-INF/scalate/templates/hello-scalate.jade")
  }
}

但我得到以下异常(即使文件存在) - 任何线索?

Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

FWIW,最里面的异常来自org.mortbay.jetty.handler.ContextHandler.getResource第 1142 行:_baseResource==null

4

1 回答 1

5

从 scalatra 邮件列表中得到了答案。问题是我正在启动 Jetty 服务器:

import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.{Context,ServletHolder}
val server = new Server(8080)
val root = new Context(server, "/", Context.SESSIONS)
root.addServlet(new ServletHolder(new FooWeb()), "/*")
server.start()

我需要在之前插入这个start()

root.setResourceBase("src/main/webapp")
于 2011-07-20T04:18:06.850 回答