Wednesday, September 18, 2013

Auto Refresh and Reload Changes When Using a Custom Env in Grails on your Local Machine



Setup Flags/Params to get Auto-Refresh/Auto-Reload of Changes Behavior in a Custom Grails Env when running Locally

   

OK, so you need to use a Custom Environment in Grails while developing and running on your local machine.  Unlike when using the basic develop Env, when you make some changes and refresh the page, the changes aren't there.  


Well, it turns out several flags and settings which are enabled by default in Dev mode will not be set when you create your own custom environment.  Many of these flags and settings include features that auto refresh and reload changes you make in the code and deploy those changes.  This is because these settings are processor intensive and you would not want these settings going to PROD.

This tutorial will show you how to enable those flags and settings so that you automatically refresh and reload changes on your local machine when running a custom env.

Just to reiterate, these settings are for development.  Don't use them on PROD.




STEP 1 - Setup the Run Config

First you want to:



  • Right-click your project
  • Select "Run As"
  • Select "Run Configurations"



How to get to the run config
Navigate to the Run Configurations Screen




Then you want to modify the grails command as such:

-reloading -Dgrails.env=custom  run-app

Make sure - reloading is the first arg! JIRA link to issue with flags here


Add custom VM params
Add params to your run config


What does this do?

It does two things:


  1. When you do a basic run-app command, it will automatically run the app in the custom environment
  2. It passes the -reloading flag 


STEP 2 - Modify your config.groovy

Yes, you can also pass these params in to the command line and add them as flags in your run config.  In my experience, things can get a little buggy and hard to manage if you pass too many flags in your run config.


This way is easier to read, modify and manage as well.


First, open your local config.groovy file.


Update your configuration:  Config.groovy location
How to find your config.groovy



Then update your local configuration by adding the following arguments to your config.groovy file:


Groovy Config parameters:  disable.auto.recompile=false and grails.gsp.enable.reload=true
Add these params to your config file


The config parameter, disable.auto.recompile=false and grails.gsp.enable.reload=true will refresh your application after you save your gsp and code changes in your IDE.


Save everything and restart your IDE.  You should see changes to GSPs and code immediately without having to restart the server when developing in Grails.







References:
Grails.org Auto Reloading Page
Grails JIRA Issue about this



RTS Labs
Software Development Blogs - BlogCatalog Blog Directory