I've inherited a Grails project that is deployed in Tomcat. I essentially have to reverse engineer what the previous engineers have done.
My question is how does Grails choose among one of the Grails environments:
So in Config.groovy there is:
environments
{
development
{
. . .
}
production
{
. . .
}
}
But how in a deployed Tomcat server is say "development" chosen over "production" when starting up Tomcat? I assumed it would be as some context or init parameter in web.xml, something like
<code>
<init-param>
<param-name>grails.environment</param-name>
<param-value>production</param-value>
</init-param>
</code>
All of the grails documentation presumes that you run
grails war your-selected-environment
but didn't design to document exactly how the war artifacts are affected.
If you run
grails test war
for example, then the war is built so it will only use the code in the 'test' specific environment blocks. No need to worry about anything in the runtime environment.
The drawback is you have to build a separate war for each environment.
Alternately, you can just generate a single war and then set an environment variable in tomcat startup for each environment that tells grails what configurations to choose. You do this by setting, for example
-Dgrails.env=test
Edit your tomcat environment file. For Tomcat 7:
/path/to/apache-tomcat-7.x.x/bin/setenv.sh
and add the grails.env system property to the command line
CATALINA_OPTS='-Xms2048m -Xmx8192m -Dgrails.env=dev';
Replace dev with the environment you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With