If you’re builing closed-source application in Grails you’ll probably want to remove GSP sources from your war. Fortunately, war script in Grails 1.2 calls GSP pre-compiler that as a result produces Java class files. However, GSP pages remain in WEB-INF/grails-app/views directory of application’s war file, although they’re not needed any more when application is packaged for production environment (because GroovyPagesTemplateEngine runs with disabled reloadEnabled option).
So, when building a war for production you can safely remove the content of your GSP files (but don’t delete them). You can do that automatically using the following script in scripts/_Events.groovy:
eventCreateWarStart = { warName, stagingDir ->
if(grailsSettings.grailsEnv == 'production') {
println "Delete content of GSP files"
def viewDirs = [new File("${stagingDir}/WEB-INF/grails-app/views")]
while(viewDirs) {
def dirs = viewDirs
viewDirs = []
dirs.each { dir ->
dir.listFiles().findAll {
if(it.isDirectory()) {
viewDirs << it
}
else if(it.name.endsWith(".gsp")) {
it.text = "This GSP file has been pre-compiled"
}
}
}
}
}
}
Using Java? Speed-up bug fixing and improve customer satisfaction using LogDigger to create detailed error reports and notifications for your web application