## Grails script, startGrails
Grails main class in startGrails is org.codehaus.groovy.grails.cli.support.GrailsStarter that sets up config to execute org.codehaus.groovy.grails.cli.GrailsScriptRunner to run Groovy scripts. Executes the Groovy script, in interactive mode if no script invoked. ~/.grails/.aliases may contain command aliases.
RunApp.groovy -> _GrailsRun.groovy instantiates GrailsProjectRunner (org.codehaus.groovy.grails.project.container.GrailsProjectRunner in grails-project-api). Also calls _GrailsWar that calls _GrailsClean and _GrailsPackage.
_GrailsPackage.groovy packageApp calls:
compilefrom_GrailsCompile.groovythat compiles Groovy and Java sources (“Packaging Grails application”).projectPackager.packageApplication()from classorg.codehaus.groovy.grails.project.packaging.GrailsProjectPackagerconfigureServerContextPaththat callsprojectPackager.configureServerContextPath()loadPlugins()from_PluginDependencies:
GrailsProjectPluginLoader#loadPlugins() calls grailsApplication.initialise(), described later.
generateWebXmlthat callsprojectPackager.generateWebXml(pluginManager).
Then runApp from _GrailsRun is called, that calls GrailsProjectRunner#runApp().
GrailsProjectRunner is a subclass of BaseSettingsApi. runApp() calls runInline which creates a server factory (by default org.grails.plugins.tomcat.TomcatServerFactory) and creates a EmbeddableServer server instance to run the server (GrailsProjectRunner#runServer) as an expolded war.
Once the server started, a StatusFinal event is triggered.
Prepares webapp; web.xml defines listener org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener and Grails dispatcher servlet org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet. It also defines Spring applicationContext.xml
GrailsDispatcherServlet is a Spring MVC DispatcherServlet. createWebApplicationContext sets up the application context, executes Grails bootstrap (GrailsConfigUtils.executeGrailsBootstraps). The parent application context is in web-app/WEB-INF/applicationContext.xml. Grails application is in that xml: GrailsApplicationFactoryBean.
setApplication(parent.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class))
It gets a GrailsWebApplicationContext, sets as webContext, and apply initializers.