如何在Play Framework 2.0中使用相对路径访问资源文件? [英] How do I access a resource file using a relative path in Play Framework 2.0?

查看:131
本文介绍了如何在Play Framework 2.0中使用相对路径访问资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问相对于Play应用程序路径的资源文件(即使打包到分发zip中)?

这是与相同的问题,但在Play 2中,其api中没有VirtualFile类. /p>

谢谢.

解决方案

签出play.api.Play.getFile()play.api.Play.getExistingFile(),它们从文件系统中获取与应用程序目录相关的文件.

一种适用于我的类似技术只是在播放开始脚本中的类路径中添加资源目录(或jar).然后,我可以使用Play.getResourceAsStream()从该目录加载文件,或在启动脚本中将资源指定为JVM参数(例如-Dconfig.resource=/my_conf/prd.conf)

How do I access a resource file relative to a Play application path (even when packaged into a distribution zip)?

This is the same problem as this, but in Play 2, which has no VirtualFile class in its api.

Thanks.

解决方案

Check out play.api.Play.getFile() and play.api.Play.getExistingFile(), which get files from the file system relative to the application directory.

A similar technique that works for me is simply to add a resource directory (or jar) to the classpath in the play start script. I can then use Play.getResourceAsStream() to load files from that directory, or specify the resource as a JVM parameter in the start script (e.g. -Dconfig.resource=/my_conf/prd.conf)

这篇关于如何在Play Framework 2.0中使用相对路径访问资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆