Dark theme | Light theme

January 23, 2010

Grails Goodness: Multiple Environments

Grails supports different environments for configuring properties. Default we get a development, test and production environment, but we are free to add our own environments. We can define the new environment in for example grails-app/conf/Config.groovy. Next we can use the environment from the command line with the -Dgrails.env= option. Here we must use our newly created environment.

// grails-app/conf/Config.groovy
environments {
    development { ws.endpoint = 'http://localhost/ws.wsdl' }
    test { ws.endpoint = 'http://test/ws.wsdl' }
    production { ws.endpoint = 'http://ws.server/complete/ws.wsdl' }
    testserver1 { ws.endpoint = 'http://testserver1/test/ws.wsdl' }
    testserver2 { ws.endpoint = 'http://testserver2/test/ws.wsdl' }

To create a new WAR file with the settings for the testserver2 environment we type the following command:

$ grails -Dgrails.env=testserver2 war