Increasing heap size for a Grails application

I had been running into a lot of issues with Grails running out of heap space on my computer and finally found a solution. In the Grails command line documentation is mentions you can set a maximum heap space when you run grails through the command line. I would keep forgetting to set this and have to restart the app.

export GRAILS_OPTS="-XX:PermSize=128m -XX:MaxPermSize=512m -Xms256m -Xmx512m"
grails run-app

I knew that had to be an easier way, so I created an Environment Variable called GRAILS_OPTS and set the value to

-XX:PermSize=128m -XX:MaxPermSize=512m -Xms256m -Xmx512m -server

Now these settings are used anytime I run grails.

Groovy, Grails and Responsive Web Design Stack Overflow

I’ve taken inspiration from Stephen Moretti and his CFOverflow twitter account and started twitter accounts for Groovy, Grails and Responsive Web Design that post the latest questions on each topic from Stack Overflow. For Groovy it posts the latest questions tagged Groovy and the same goes for Grails. I originally set these up as just one feed, but the questions coming in to the two feeds don’t really overlap as much as I thought they might so I decided to split them into two accounts.

For the Responsive Web Design account the latest Stack Overflow posts tagged “media queries” or “responsive design” are posted.

Stephen said he added some filters to prevent duplicates from posting, but I haven’t done that yet. If duplicates start showing up in the feeds I will take a look at the filters.

If anyone thinks other feeds should be added to these accounts let me know and I can get them added. Any feedback at all in appreciated

Groovy questions
Grails questions
Responsive Web Design questions

Using grails assets when you can’t use the asset tag

In Grails 2.4+ the asset pipeline plugin is included by default and you can access files in the assets folder by using an asset tag


  <asset:javascript src="application.js"/>
  <asset:stylesheet src="application.css"/>
  <asset:image src="logo.png" width="200" height="200"/>

However, it’s not always feasible to be able to use that syntax. One example is when loading an svg image with a png fallback. The code would ideally look like this when the HTML is generated.


<svg width="180" height="60">
  <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="logo.svg" src="logo.png"></image>
</svg>

Rather than using an asset tag you can use assetPath() to find the file just like using the asset tag would do. In this case our SVG and PNG images are stored in variables named logoSVG and logoPNG. When the HTML is generated the resulting HTML is as desired.


<svg width="180" height="60">
  <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${assetPath(src: logoSVG)}" src="${assetPath(src: logoPNG)}"></image>
</svg>

One important thing to note is the asset plugin is not recursive, so if your file is not located in assets/images you will need to include the path relative to the images folder in your src. If your images were in an imgs folder the syntax would be like so


<svg width="180" height="60">
  <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${assetPath(src: 'imgs/' + logoSVG)}" src="${assetPath(src: 'imgs/' + logoPNG)}"></image>
</svg>

Grails – Reloading a service without stopping your app

When a grails application is started most Grails artificats are reloaded as they are changed – controllers, filters, tag libraries, but the opposite is true if you strongly type your services like below.

FakeService fakeService

However if you use untyped injected like

def fakeService

then the service will be reloaded as changes are made. This may have been obvious to most people, but I was originally going through the hassle of either restarting my app after each change (huge time waster) or creating a fakeServiceHelper where I made all my changes and introducing a needless extra layer to my application to avoid restarting my app after each change.