Sunday, 10 July 2016

Episode 1- Booting GRAILS with GRETTY

Since my last blog on Grails, I have been trying to start to quick deploy my app in jetty, while using run-app command, which by default uses tomcat 7 container.

However by preparing war with gradle and deploying it in jetty 8.1.17 externally is a success, but for quick and easy deployment I am keen on implementing run-app with jetty.

I changed the required runtime dependencies in build.gradle, started my app, in the command prompt I can see my app got deployed, but I was not able to access it. I tried by using different versions jetty server but with no success.

After a bit of searching I came to know about GRETTY plugin. Its configuration properties and good documentation helped me a lot and I was able to deploy my app with a single go using jetty 9 with appStart tasks. So thanks to Gretty!!!

The required configuration can be found at build.gradle at Here

Please Find my codebase at GitHub. Even I can pass the environment for which I want to build just like we pass while using grails run-app command.

Here we use:

gradle -Penv=<<env_name>> appStart

Now the env variable is then captured in the gretty task and is made available as JVM parameter. As:

gretty {
    // supported values:
    // 'jetty7', 'jetty8', 'jetty9', 'tomcat7', 'tomcat8'
  port = 8888
    servletContainer = 'jetty9'
    jvmArgs = ["-Dgrails.env=$env"]

    /**
     * This jvmArg is used to set config location
     * where Spring boot will look for Config Files
     */
    // '-Dspring.config.location=classpath:/config/'
}

suppose if we use -Penv=dev, then development environment related configuration properties are loaded from application.yml.
For the sake of clarity, I have defined two application.properties in the src/main/resources folder as application-development.yml and another as application-staging.yml

when we use -Penv=dev along with development environment related configuration from application.yml, properties from application-development.yml are alsoe being loaded. That's Grails speciality

Now if we use -Penv=staging, along with staging environment related configuration from application.yml (if any, since it is custom environment that I have defined, there will be no block for staging in application.yml when we create a Grails application using create-app) properties from staging-development.yml are alsoe being loaded.

Properties access code from both the yml files, is there in Bootstrap.groovy, so see the whole thing in operation.

I have tried explore Spring JMS with Grails.

Here are the DETAILS
View Subhankar Paul's profile on LinkedIn

No comments:

Post a Comment