Grails 2.4.4 - How to store config variable at war phase and get it in a Tomcat env?

85 views Asked by At

When running "war" command from Grails, I want to store the build commit for use it in a GSP thereafter.

In my Config.groovy

def proc = 'git rev-parse HEAD'.execute() proc.waitFor() build_commit.number = proc.in.text

In my GSP

<p>${grailsApplication.config.build_commit.number}</p>

Everything work fine when I run my app with "run app" command but when I deploy my War on Tomcat the information is no longer available.

Is it because Config.groovy is reevaluate when the war is deploy ?

I also try to write programmatically the build commit to application.properties but I couldn't find a way to do that.. If it's possible, I also need to know how to detect a Tomcat env for avoid rewriting a blank value.

Any help will be appreciate.

1

There are 1 answers

1
Daniel On

If you need persistent data (like your build_commit.number) you should investigate integrating your application with a database, or writing this to a file on your filesystem. Either one will require access from both your development environment (where you run "run app") and your production environment (where you deploy the war to tomcat).