玩! Framework 2.0路径-播放运行与播放开始 [英] Play! Framework 2.0 paths - play run vs play start

查看:71
本文介绍了玩! Framework 2.0路径-播放运行与播放开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件存储到剧本中的文件夹中!项目,我对路径有疑问.我的解决方案正在工作,但我认为该解决方案不够理想.

I'm storing files to a folder in a play! project and I have a question about paths. My solution is working, but I think the solution is sub optimal.

我当前的解决方案:

public static String getStoragePath(){
    String pubDir =  Play.application().configuration().getString("pathToFiles");

    if(Play.isProd()){ 
        String prodDir = Play.application().configuration().getString("productionPath"); 
        //prodDir variable is "target/scala-2.9.1/classes"

        return Play.application().path().getAbsolutePath() + "/" + prodDir + "/" + pubDir;
    }else{
        return Play.application().path().getAbsolutePath() + "/" + pubDir;
    }
}

我的问题:

我这样做是因为在运行"play run"和"play start"时路径是不同的. 有办法避免使用此if块吗?我不想依赖于配置文件中的productionPath字符串.

I do it like this because the paths are different when running "play run" and "play start". Is there a way to avoid using this if-block? I dont want to be dependent on the productionPath string in my configuration file.

推荐答案

使用conf文件是实现此目的的方法.只需为您的生产环境使用其他conf文件,就无需在代码中进行大量if(isProd ...)检查.

Using the conf file is the way to do it. Just use a different conf file for your production enviroment and you will not need to have a bunch of if(isProd...) checks in your code.

Play 2可以使用替代/扩展配置文件,如文档中所述的 ( 指定备用配置文件 部分).另外,您可以创建简单的bash脚本(或Windows中的.bat文件)以所需的模式启动应用程序,而无需每次都指定备用文件.

Play 2 has ability to use alternative/extending configuration files as described in documentation (Specifying alternative configuration file section). Additionally you can create simple bash script (or .bat file in Windows) to start the application in desired mode without need to specify alternative file each time.

这篇关于玩! Framework 2.0路径-播放运行与播放开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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