5

Using Grails 2.0.4. In building emails, I use a lot of images with absolute paths. Each one results in an annoying log entry. Is there an easy fix? They DO exist, it just seems the resource plugin doesn't like absolute paths. This happens outside of localhost / dev environment too.

<img src="${resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" />

results in

WARN  resource.ResourceTagLib  - Invocation of <r:resource> for a resource that apparently doesn't exist: http://localhost:8080/images/brochure/arrow_up.png
Peter
  • 29,498
  • 21
  • 89
  • 122

4 Answers4

4

The solution that has been working with me for Grails 2.1.x and above (including the newest 2.3.x) is adding these entries to your log4j config block in Config.groovy - no other code changes needed.

 log4j = {
           //your other stuff ...
            error 'grails.app.services.org.grails.plugin.resource'
            error 'grails.app.taglib.org.grails.plugin.resource'
            error 'grails.app.resourceMappers.org.grails.plugin.resource'
}
Peter
  • 29,498
  • 21
  • 89
  • 122
0

I know this is an old question, but it still seems to be an issue with Grails 2.3.x. There is comment above the resource closure in ResourceTagLib that says:

@todo this currently won't work for absolute="true" invocations, it should just passthrough these

In order to remove the warnings in the log, I overrode the resource closure, changing this bit:

...
if (!info.debug && log.warnEnabled) {
    log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}"
}
...

to this:

...
if (attrs.absolute != true && !info.debug && log.warnEnabled) {
    log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}"
}
...
rcgeorge23
  • 3,594
  • 4
  • 29
  • 54
0

It appears to happen only when you try to use a sub directory when using the dir param. You would need to specify a uri. I'm assuming that dir can only be a single level directory.

You could try the following (from plugin docs) :

<r:img uri="images/logo.png" width="100" height="50"/>
pjdicke
  • 299
  • 2
  • 12
-1

uou are using 'grails-resources' plugin. It has also tag 'resource'. try to use direct G-tag:

<img src="${g.resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" />

or use R-tag from resources plugin (RECOMMENDED):

<img src="${r.resource(uri: 'images/brochure/arrow_up.png')}" />

Get more info here

jenk
  • 1,043
  • 7
  • 8
  • Those both simply delegate to the resources plugin – Peter Jul 18 '12 at 05:07
  • 1
    no. i used namespace to direct definition. If resource-plugin is installed 'resource' tag is associated with 'r' namespace by default. – jenk Jul 18 '12 at 07:10