简体   繁体   English

如何设置 grails 环境变量?

[英]How do i set up a grails environment variable?

I have a folder in my d drive.files in this drive i am using in my controller.so in controller i am specifying tht folder name for to each file recurse.But after development files may be saved in any other drive.so I want have environment variable for it.how to do that我的 d 驱动器中有一个文件夹。我在 controller.so 在 controller 中使用这个驱动器中的文件有它的环境变量。如何做到这一点

It sounds like a configuration parameter would be better than an environment variable.听起来配置参数比环境变量更好。 Config.groovy is environment aware, so you can specify different values for development, production, etc. Config.groovy是环境感知的,因此您可以为开发、生产等指定不同的值。

environments {
    production {
        fileLocation = "D:/"
    }
    development {
        fileLocation "/somewhere/else"
    }
    test {
        fileLocation "/production/somewhere"
    }    
}

You can read the value of this parameter with:您可以通过以下方式读取此参数的值:

def fileLocation = org.codehaus.groovy.grails.commons.ConfigurationHolder.config?.fileLocation

in grails 1.4 ConfigurationHolder is deprecated, so you should read config parameters using this instead:在 grails 1.4 ConfigurationHolder已弃用,因此您应该使用以下方式读取配置参数:

def fileLocation = grailsApplication.config.fileLocation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在python 3中从文件中读取字符串,直到设置的字符(例如,读取直至单词“ hello world¬这是一个字符串”) - how do i read a string from a file up to a set character (for example reading the words “hello world ¬ this is a string” up to the¬) in python 3 如何使用变量设置以fprintf'%s'格式输出的字符数? - How do I set the number of characters output in a fprintf '%s' format using a variable? 在POSIX环境中,如何跟踪子进程访问的文件? - In a POSIX environment, how do I track files accessed by a child process? grails应用程序中的“打开文件太多” - 如何正确关闭打开的文件和流? - “Too many open files” in a grails application - how do I close opened files and streams correctly? 如何将 PHP 文件加载到变量中? - How do I load a PHP file into a variable? 如何在 VimScript 中序列化变量? - How do I serialize a variable in VimScript? 如何将basename放入变量? - How do I put basename into a variable? 如何在Linux中设置文件时间范围? - How do I set file timesamps in Linux? 如何以编程方式设置文件标签 - How Do I Programmatically Set a File Tag 如何将命令 output 保存到变量中,以及如何将该变量用作 Powershell 中的命令参数? - How do I save a command output to a variable, and how do I use that variable as command parameter in Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM