Search code examples
javagrailsgroovysitemesh

Getting started with Grails Resources Plugin


I am new to using Grails plugins and this is most likely a novice mistake, but I cannot find documentation that helps me, so here we go.

I have added the following file to grails-app/conf : appResources.groovy

//appResources.groovy
modules = {
     css{
         resource url:"/css/main.css"
     }
}

and in my layout file main.gsp I use <r:layoutResources /> in the head and right before </body>. So far so good no errors.

Now in my view gsp I have this (in part):

//myView.gsp
<head>
    <title>title</title>
    <meta name="layout" content="main" />
    <r:require      module="css"       />
</head>

When go to view the page I now get the following error:

Exception Message: No module found with name [css]
Caused by: Error executing tag <g:applyLayout>: Error executing tag <r:layoutResources>: ...

I've done my reading, and I think I need to do something in Config.groovy to get grails to read appResources.groovy but I have no idea what to write. Thanks everyone!


Solution

  • The standard filename is ApplicationResources.groovy. It will be picked up automatically.

    Be sure to set grails.resources.work.dir in Config.groovy to a stable location in order to prevent missing resource issues in production deployment.