Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何访问相对于 Play 应用程序路径的资源文件(即使打包到分发 zip 中)?
这与此问题相同,但在 Play 2 中,其 api 中没有 VirtualFile 类。
谢谢。
查看play.api.Play.getFile()and play.api.Play.getExistingFile(),它从相对于应用程序目录的文件系统中获取文件。
play.api.Play.getFile()
play.api.Play.getExistingFile()
一种对我有用的类似技术只是将资源目录(或 jar)添加到 play start 脚本中的类路径中。然后我可以使用 Play.getResourceAsStream() 从该目录加载文件,或者在启动脚本中将资源指定为 JVM 参数(例如-Dconfig.resource=/my_conf/prd.conf)
-Dconfig.resource=/my_conf/prd.conf