1

When I build a war file for my Grails application via grails war it still contains some groovy files.

After the war-filed is deployed on an application server, when and how are this files compiled to java bytecode?

sofarsogood
  • 291
  • 2
  • 13

2 Answers2

5

The templates are there for dynamic scaffolding. For example if you have a controller like this

class PersonController {
   static scaffold = Person
}

then it'll use the template to create a controller at runtime. This isn't very often used in real apps - it's more for demos and getting started - but it's an option. The dynamically generated controller and GSPs are created based on the templates and compiled in-memory.

The groovy-all jar does have code that can compile Groovy source, but that's because it's the "-all" jar. Just because it's there doesn't mean it's necessarily used. In general all compilation is done when building the war, including precompiling GSPs. This is for performance - you want the app to be as fast as possible in production.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • That's interesting. Do I understand you correctly, that it's possible to deploy grails apps without any groovy files included and without the groovy-all.jar? Do you have any hints on the technical details? – sofarsogood Jun 30 '11 at 20:03
  • Absolutely not. Grails uses Groovy both for compilation and at runtime - it depends heavily on Groovy for the dynamic behavior in GORM (e.g. `Person.findByUsername()`) and in most aspects of the application lifecycle. I assume it's safe to remove the .groovy template(s) but why do you care? – Burt Beckwith Jun 30 '11 at 20:46
  • Well, there are concerns that it could be possible to make some dynamic modifications to a running grails app in production. So first I try to understand better how Grails and the Groovy stuff actually works, second I try to find out what parts actually aren't needed and can be removed from the app. And I still don't get what can be done with this all-inclusive groovy-all.jar – sofarsogood Jun 30 '11 at 21:09
1

The groovy files are compiled into class files before you package into the war. Check the WEB-INF/classes directory

Dhanush Gopinath
  • 5,652
  • 6
  • 37
  • 68
  • Most of them, but not all. There is still a Grails generated groovy file at WEB-INF/templates/scaffolding/Controller.groovy Besides that the application contains a groovy-all.jar which seems to contain everything that is necessary to compile groovy files. – sofarsogood Jun 30 '11 at 17:17