Question

I need, in Config.groovy, the $userHome variable. It works in my development machine, infact I use the following:

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

or

 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}/"
        ...
       }
 }

In my production machine, it seems that $userHome is usr/share/tomcat7 and not the correct Home path. Why do I have this behaviour?

Was it helpful?

Solution

That probably is the correct behaviour - it looks like your production Tomcat is running as a specific system user (probably called tomcat7 or similar) whose home directory is /usr/share/tomcat7.

If you want to set up different values for a configuration option for the development and production systems, the standard way to do that is to use the 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}/"    
  }
}

Now in development mode it will use the standard path involving ${userHome} but when running in production mode (when you build a grails prod war and deploy it to tomcat) it will use the setting from inside the environments block. You can likewise have a development block inside environments for settings that apply only in development mode.

Note that Config.groovy is parsed from top to bottom, so the generic settings must be ahead of the environment-specific ones.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top