7
votes

When you compile a grails war, I understand that the .groovy code is compiled in to bytecode class files, but I don't understand how the container (say, tomcat), knows how to compile the GSPs when they are requested. Do the containers understand GSP? Does the fact that grails is installed on the server hook into the containers?

Also, when the GSP is used for the first time, it is compiled then on demand and only once. Is this correct? Thanks.

3
To my knowledge, GSPs are already precompiled. If you extract the WAR file you can confirm this for yourself. - Gregg

3 Answers

12
votes

Do the containers understand GSP?

The GSPs are actually compiled into class files when the war is built, and not at runtime by tomcat - if you unzip the war file, you can look at what it does (look at the unzipped WEB-INF/classes directory):

...
gsp_appname_controllerNameviewName_gsp.class
gsp_appname_controllerNameanotherViewName_gsp.class
...

The container doesn't need to do anything at runtime, since everything's pre-compiled.

Does the fact that grails is installed on the server hook into the containers?

It does not; everything needed for the application to run is included in the war, so grails being installed on the container's server makes no difference.

3
votes

Ok, so just found this on the mailing list:

Since grails 1.2 the gsps are pre compiled when generating the war file.

1
votes

GSPs are like JSPs, they are ultimately servlets.

So, when you build a .war file, your GSP are precompiled to servlets and included in your WEB-INF/classes .war folder. (they start with gsp_controlleraction_**.class)

So, no, Tomcat does not know how to compile GSP, but it can execute the servlets.

Vincent.