Grails supports the concept of environments. You can specify the environment to use before any command:
grails run-app // runs with the default “development” data source
grails dev run-app // runs with the “development” data source
grails prod run-app // runs with the production data source
grails -Dgrails.env=mycustomenv run-app// specific a custom environment
grails test run-app // runs with the test data source
These options are also available when packaging the application as a WAR file, although in this case the default data source used is _production_:
grails war// Packages the application with the “production” data source
grails dev war // Packages the application with the “development” data source
grails prod war // Packages the application with the “production” data source
You can use word ‘production‘ instead of ‘prod‘ and use ‘development‘ instead of ‘dev‘.
The short and full names of the environments defined by Grails are shown below:
You can take advantage of these environments you can have different DataSource settings per environment or different Config settings.
Datasource settings:
// environment specific settings
environments {
development {
dataSource {
dbCreate = “update” // one of ‘create’, ‘create-drop’, ‘update’, ‘validate’, ”
url = “jdbc:mysql://localhost/database_name?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true”
username = “XXX”
password = “XXX”
}
}
test {
dataSource {
dbCreate = “update”
url = “jdbc:mysql://localhost/database_name? useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true”
username = “XXX”
password = “XXX”
}
}
production {
dataSource {
dbCreate = “update”
url = “jdbc:mysql://localhost/database_name? useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true”
username = “XXX”
password = “XXX”
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery=”SELECT 1″
}
}
}
}
Config.groovy settings:
environments {
production {
grails.serverURL = “http://www.changeme.com”
grails.dbconsole.enabled = true
grails.dbconsole.urlRoot = ‘/admin/dbconsole’
}
development {
grails.serverURL = “http://localhost:8080/${appName}”
}
test {
grails.serverURL = “http://localhost:8080/${appName}”
}
}
ProsperaSoft offers Grails development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Grails experts and consultants.