Scalatra中的Scalate ResourceNotFoundException

时间:2011-07-19 06:42:14

标签: scala scalate scalatra

我正在尝试基于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

1 个答案:

答案 0 :(得分: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")