Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Grails Environment in Tomcat

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.

like image 343
igaz Avatar asked Dec 08 '22 12:12

igaz


2 Answers

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
like image 129
Ed OConnor-Giles Avatar answered Dec 29 '22 10:12

Ed OConnor-Giles


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

like image 42
Louis GRIGNON Avatar answered Dec 29 '22 11:12

Louis GRIGNON