7

Seems that Grails does automatically recompile my GSP pages, but not my controllers. It used to work with the previous version of Grails. Any idea what I can look for?

Using Grails 2.1.0 on OSX Snow Leopard.

Note: This is similar to this issue

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • So you use grails rA? Try starting grails and running run-app – Chris Aug 25 '12 at 10:51
  • 1
    which jvm are you using? per the docs - Grails 2.1 reloading mechanism no longer uses class loaders, but instead uses a JVM agent to reload changes to class files. – chrislovecnm Aug 26 '12 at 19:51
  • @chrislovecnm java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-10M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) – sparkyspider Sep 05 '12 at 06:37
  • @MarkvanWyk have you tried 1.7? – chrislovecnm Sep 05 '12 at 17:56
  • Got Grails running on JDK 1.7 with Grails 2.1.1 - Same thing's starting to happen... – sparkyspider Oct 02 '12 at 18:15
  • Is it broken for every grails project in your machine or just one in specific? I've seem this happening when a file was saved with a severe enough groovy syntax flaw. – Raphael Oct 03 '12 at 18:04
  • Hey Mark, I had another thought as I was running into this sporadically in recent days. How much RAM do you have on your laptop and are you thrashing? I've recently upgraded my RAM (as I was thrashing myself) and noticed that my apps are now reloading everything constantly and as it should. – Jonathan Larson Oct 23 '12 at 18:20
  • If you are using intellij and grails 2.2.0 see this post: http://youtrack.jetbrains.com/issue/IDEA-97889. –  Dec 30 '12 at 20:00

4 Answers4

7

Disclaimer: Auto-reload has always worked for me on my Mac.

I've found a couple of things that might be useful.

First, it appears that running a custom environment (that isn't dev) disables auto-reload (see this stackoverflow post), so you'll want to follow the directions in that post if you're running the application that way.

Second, if you're running the app as a war, for sure auto-reload is turned off. (See the Grails Auto-Reload Page)

Third, I've found that using a Grails IDE (such as IntelliJ or SpringSource) really adds a lot of stability to the Grails development environment. For example, IntelliJ doesn't use the Grails shell file that comes with the binary download. It manually invokes the Grails jars and bootstraps.

My questions to you are:

What does the rest of your environment look like? How are you running your application (run-app or another container)?

What Grails plugins do you have installed (the Grails documentation says the tomcat plugin is configured for optimal auto-reloading)?

Do you have any other Grails binaries downloaded on your computer (could cause confusion when it's trying to load)?

And finally, are you able to reproduce this issue in a clean environment (meaning new Grails binary, fresh Grails create-app)?

I'd also recommend reading the Deployment section of the Grails documentation (found here). It has some pertinent information regarding the reloading.

I apologize for the longwinded and potentially non-answering answer, but I hope this has sparked an idea or two. Let me know how things turn out!

Community
  • 1
  • 1
Jonathan Larson
  • 302
  • 2
  • 9
  • Hi @Jonathan, thanks so much for your answer. To tell you the truth, I can't tell what makes it stop reloading and then start again. Seems that after a while it stops, then if I restart my machine, it starts working again - which makes it even more difficult to debug. I'm running Grails 2.1.1 command-line on Max OS X Mountain Lion with JDK 7 (RunnApp / Dev Mode). Thanks for all the tips! Welcome to StackOverflow! With answers like this, you'll have thousands of points in no time! – sparkyspider Oct 04 '12 at 06:05
  • @Mark, thanks so much for the compliments. I hope to become a valuable reference for people in the years to come. I have a pretty similar set-up to you with the exception of the JDK (I'm running Mac's default 1.6, sadly). However, I've been using an IDE to run my Grails dev env. I'm going to try your exact set-up all day today and see if I run into the same issue. I will keep you updated! – Jonathan Larson Oct 04 '12 at 13:37
  • @Mark, so I spent the last part of the week using your set-up and unfortunately, I wasn't able to recreate your situation. I did notice, however, that some of the plugins were having an effect on the reloading of my resources. I know that has nothing to do with controller reloading, but just figured I'd throw that out there. Best of luck finding your answer! – Jonathan Larson Oct 08 '12 at 13:42
4

If you name the package names on your controllers incorrectly (as in the folder structure does not agree with the package declaration), the application will still run and no errors will be reported, but auto-reloading will not work.

sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • So check your package names carefully - especially after refectoring! – sparkyspider Oct 24 '12 at 15:54
  • Do you have any examples of what does vs. what doesn't work? I'm running into this same issue, but things seem to be named correctly. – cdeszaq Dec 03 '12 at 14:31
  • 1
    Also, you have to run "grails run-app", as a single command and not grails, then in the grails prompt, run-app. – sparkyspider Dec 04 '12 at 05:46
  • The "grails run-app" vs. "grails", "run-app" distinction is what bit me, thanks for that clarification. Also, I'm running with a -D param, so GRAILS-8951 seems relevant. – Lyle Dec 27 '12 at 19:46
0

I had this problem when I had a BaseController class from which other controllers were derived. If I make changes to BaseController class such as adding a method or closure, change a method name, import some classes etc, the whole class reloading feature in Grails will come to a grinding halt.

The only solution that worked for me was to delete the target directory into which all classes were compiled. At least that way I did not have to restart the server every time which saved me from having to wait about 30 seconds to display the start page. It could be pretty annoying when class reloading feature does not work as expected.

Grails auto-reloading feature is not without quirks. Some of these quirks are ultimately related to java and how class loading works in servlet container environment. I hope the Grails team will make it a priority to provide seamless class reloading for Grails like other scripting environments( ruby, PHP, python or play framework) because some other aspects of this framework is such a pleasure to deal with.

Indra
  • 471
  • 3
  • 5
-1

Strange, I've never had a problem with this. Are you sure that your controllers are compiling correctly, no typos? I've found that it generally only takes a second or two to see a change reflected in the controllers. Domain object changes require a restart (they usually wipe your saved data) and I've found that sometimes a change to a spring managed resource (like an injected service) dont' take. But controllers and GSP pages recompile 97% of the time :)

I go between GGTS (eclipse) and the command line run-app and it almost always works for me. Are you doing any sort of caching perhaps? I'm running JDK 1.6 on Lion, grails 2.1.1

Usually you will see output telling you that a file has recompiled within a second or two of hitting save.

Rick Mangi
  • 3,761
  • 1
  • 14
  • 17