Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Detecting the Grails Environment in a GSP

DZone's Guide to

Detecting the Grails Environment in a GSP

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Last night I needed to make sure that my analytics tracking script was not running anywhere but in my production environment. After reading another blog post I came up with this simple GSP if block.

**** UPDATE ****

Thanks Burt for the comment pointing out that the original code I posted is actually deprecated and for pointing out a better way for testing environment.

According to the docs (and Burt), this is the correct way to test for environment in a GSP.

<g:if env="production">
<!-- Markup to include ONLY when in production -->
</g:if>

**** The code below is deprecated ****

<g:if test="${ grails.util.GrailsUtil.getEnvironment().equals(org.codehaus.groovy.grails.commons.GrailsApplication.ENV_PRODUCTION) }">
<!-- Markup to include ONLY when in production -->
</g:if>

Hope this helps others who are looking to do the same within their GSPs.

Detecting the Grails Environment in a GSP

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Steve Good, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}