Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static Strings in Grails Interactive mode

I have a grails application which I am running via grails interactive mode. This application contains services, tagLibs, gsps etc but most importantly it contains groovy files in the src/groovy folder.

One of these groovy files is called AppConstants.groovy and contains a multitude of static variables i.e.

public static final String VARIABLE1 = "VARIABLE VALUE"

When running this in non interactive mode I get no problems, any updates made to this variable are reflected in the running app when it is next deployed. In interactive mode however, any changes made to the VARIABLE1 variable are not reflected in the app even if you call exit and run-app. For the changes to be reflected The interactive mode must be exited and restarted.

At first I thought this might be a cache problem and that my static final variables were being cached and since the JVM was not being restarted that this cache was never being updated. I have however noticed that adding in a new variable, one which has never existed in the application before, is not available to the rest of my application until interactive mode is restarted.

Any ideas what the reason behind this is? The class is being compiled as I can see this in the interactive console so one would expect any changes to be reflected in the application, not necessarily while it is running but at least with an exit followed by a run-app.

Extra Info: Grails version 2.1.0

like image 214
Jon Taylor Avatar asked Nov 12 '22 15:11

Jon Taylor


1 Answers

Did a little testing and here is what I found:

  1. Starting the process without -reloading never allowed the variables to be updated - so start as grails -reloading or grails -reloading run-app

  2. Non final variables WOULD reload correctly when starting the process as above. So public static String VARIABLE1 = "VARIABLE VALUE" does reload and show when I update the value

  3. final variables would not reload. So public static final String VARIABLE1 = "VARIABLE VALUE" would not reload and show new value.

I even created several variables, some final and some not. As long as I used -reloading the non-final variables would reload but final would not.

public static final String VARIABLE1 = "VARIABLE VALUE"
public static String VARIABLE2 = "NON FINAL VARIABLE VALUE"

In this scenario VARIABLE1 would not change until restart - VARIABLE2 changes when updated and saved.

like image 151
Kelly Avatar answered Nov 15 '22 06:11

Kelly