Scalatra:从已部署的应用程序访问文件路径

时间:2015-04-07 12:19:35

标签: scalatra scalatra-sbt

我需要在Scalatra应用程序中访问服务器上的文件路径。如果没有war文件,下面的文件存储在/ src / main / resources / data位置。

  

this.getClass.getResource( “/数据”)。的getPath

但是,对于已部署的应用程序,这同样不起作用。任何想法我应该如何获得上下文。

谢谢,

1 个答案:

答案 0 :(得分:0)

这个问题与How to get the path of a running JAR file?几乎相同 但是,在Scala案例中,您可以使用:

val context: ServletContext = getServletContext()
val fullPath = context.getRealPath("/WEB-INF/web.xml")

例如,要查找web.xml是: File path to resource in our war/WEB-INF folder?

sstream
相关问题