grails - grails userHome变量

标签 grails configuration home-directory

在Config.groovy中,我需要$ userHome变量。
它可以在我的开发机器上工作,实际上我使用以下命令:

environments {
   development {
           grails.plugin.elfinder.rootDir = 
                   "${userHome}/docm_patients_doc/{patientcf}/"
            ...
    } 
   production {
           grails.plugin.elfinder.rootDir = 
                   "${userHome}/docm_patients_doc/{patientcf}/"
            ...
    } 
}

要么
 environments {
   development {
       grails.plugin.elfinder.rootDir =
             "${System.properties.'user.home'}/docm_patients_doc/{patientcf}/"
        ...
       }
  production {
       grails.plugin.elfinder.rootDir =
             "${System.properties.'user.home'}/docm_patients_doc/{patientcf}/"
        ...
       }
 }

在我的生产机器中,$ userHome似乎是usr/share/tomcat7,而不是正确的Home路径。
为什么我有这种行为?

最佳答案

这可能是正确的行为-看起来您的生产Tomcat正在以其主目录为/usr/share/tomcat7的特定系统用户(可能称为tomcat7或类似名称)运行。

如果要为开发和生产系统的配置选项设置不同的值,则执行此操作的标准方法是使用 environments mechanism

// standard value
grails.plugin.elfinder.rootDir = "${userHome}/docm_patients_doc/{patientcf}/"    

environments {
  production {
    // override the value for the production environment
    grails.plugin.elfinder.rootDir = "/data/docm_patients_doc/{patientcf}/"    
  }
}

现在处于开发模式下,它将使用涉及${userHome}的标准路径,但是在生产模式下运行时(当您构建grails prod war并将其部署到tomcat时),它将使用environments块内部的设置。您也可以在development内有一个environments块,用于仅适用于开发模式的设置。

注意Config.groovy是从上到下解析的,因此常规设置必须在特定于环境的设置之前。

关于grails - grails userHome变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21314368/

相关文章:

javascript - Grails 刷新谷歌图表

c# - 读取外部配置文件

c++ - 格式错误的 C 或 C++ 程序是否保证在 Visual Studio 中的 DEBUG 配置下崩溃

java - 从 JWS 签名的 jar 中获取用户主文件夹

linux - 我如何在 Makefile 中获取用户名?

grails - 在构造函数中使用 def 时 Gradle 失败

grails - 查找带有 "+"的电子邮件时,通过电子邮件获取失败

java - Grails 从请求中提取正文数据

configuration - 更新时如何配置bugzilla使其不前进到下一个bug?

linux - 为什么我不能访问这个文件夹?