Search code examples
grailsgrails-resources-plugin

r:img leads to unlocated resource


After upgrading grails resources to the latest version, I am not able to show images. Here is what I have tried;

<li><r:img file="zeitfest.png" dir="images" /></li>
<li><r:img uri="/images/zeitfest.png" /></li>
<li><g:img uri="/images/zeitfest.png" /></li>
<li><g:img plugin="zeitfest-office" uri="/images/zeitfest.png" /></li>

Using run-app everything works fine, however using war and running inside tomcat, I always get this:

[http-apr-8080-exec-7] ERROR org.grails.plugin.resource.ResourceMeta - Resource not found: /images/zeitfest.png
[http-apr-8080-exec-7] WARN org.grails.plugin.resource.util.ResourceMetaStore - Cannot locate resource [/images/zeitfest.png]

I added

grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', "*.css", "*.js"]
grails.resources.adhoc.includes = ['/images/**', '/css/**', '/js/**', '/plugins/**']

grails.resources.mappers.cssrewriter.includes = ['**/*.css', '**/*.less']
grails.resources.mappers.csspreprocessor.includes = ['**/*.css', '**/*.less']

to my Config.groovy. It still does not show.

I even tried to reference the image from the resource bundle but it does not work.

images {
    resource url:'images/zeitfest.png'
    resource url:[plugin: "zeitfestOffice", dir: "images", file: "zeitfest.png"]
}

What could i check? Other images referenced from css files works fine and rewriting is going on.

Using 1.2.13 of resource plugin.


Solution

  • The issue was, that I rendered an image from a plugin (but within this plugin). Therefore the plugin tag has to be used everywhere. However the combination with URI is not working. So the missing combination above was:

    <li><g:img plugin="zeitfest-office" dir="images" file="zeitfest.png" /></li>
    

    This is the only combination which will work!