edvinasbartkus/grails-coffeescript-resources — Issue #6: Crash when deployed as a war
Author: jfaissolle
Created: 2012-01-13 09:51:59+00:00
State: open

Hello,

when I deploy my application as a war in Tomcat, the plugin tries to compile the coffee sources during the spring configuration phase (because of the code in doWithApplicationContext). This breaks because the source path is not found in this environment. I think that script compilation should not be part of Spring initialization.

I currently use the following workaround / hack in order to be able to use the plugin in dev as well as in prod mode.

scripts/_Events.groovy

``` groovy
import grails.util.GrailsUtil
import grails.util.Environment

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

eventCompileEnd = { source ->
if (Environment.current == Environment.PRODUCTION) {
def moduleManageClass = classLoader.loadClass("org.grails.plugins.coffeescript.ModuleManager")

def config = new ConfigObject()
config.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('Config')))
CH.setConfig(config)

moduleManageClass.newInstance().compileModules()
}
}
```

grails-app/conf/spring/resources.groovy

``` groovy
import grails.util.Environment
// Place your Spring DSL code here

// Place your Spring DSL code here
beans = {

// HACK
if (Environment.current == Environment.PRODUCTION) {
org.grails.plugins.coffeescript.ModuleManager.metaClass.compileModules = { ->
println 'Coffee compilation deactivated'
}
}
// -HACK
}
```