I am using Groovy on Grails and the resources plugin is configured.
I have this scenario:
-
I have a product, which has multiple images.
-
The admin can delete any image.
The logic is that when the admin clicks “Delete”, I remove the file (and its thumb file) from the file system.
The whole process works smoothly, but after some time (5-6 minutes), when the resources plugin once again refreshes its resources, it throws an error saying that, “some module depends on resource [path/to/file] but the file was not found”.
The stack trace is as follows:
2012-08-10 12:49:41,159 [http-8080-2] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /
Stacktrace follows:
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <r:layoutResources>: Module [__@adhoc-files@__] depends on resource [/images/product/p312roduct/original/Candle_4.jpg] but the file cannot be found at /home/desktop2/finalWorkspace3/ds/grails-app/views/layouts/main.gsp:13
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp$_run_closure1.doCall(main.gsp:13)
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp$_run_closure1.doCall(main.gsp)
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp.run(main.gsp:17)
at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:44)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:197)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:171)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.IllegalArgumentException: Module [__@adhoc-files@__] depends on resource [/images/product/p312roduct/original/Candle_4.jpg] but the file cannot be found
at org.grails.plugin.resource.ResourceTagLib$_closure8.doCall(ResourceTagLib.groovy:463)
at org.grails.plugin.resource.ResourceTagLib.invokeMethod(ResourceTagLib.groovy)
at org.grails.plugin.resource.ResourceTagLib$_closure6.doCall(ResourceTagLib.groovy:387)
... 7 more
2012-08-10 12:49:41,172 [http-8080-2] ERROR pages.GroovyPagesServlet - Error processing GSP: Error executing tag <r:layoutResources>: Module [__@adhoc-files@__] depends on resource [/images/product/p312roduct/original/Candle_4.jpg] but the file cannot be found at /home/desktop2/finalWorkspace3/ds/grails-app/views/layouts/main.gsp:13
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <r:layoutResources>: Module [__@adhoc-files@__] depends on resource [/images/product/p312roduct/original/Candle_4.jpg] but the file cannot be found at /home/desktop2/finalWorkspace3/ds/grails-app/views/layouts/main.gsp:13
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp$_run_closure1.doCall(main.gsp:13)
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp$_run_closure1.doCall(main.gsp)
at home_desktop2_finalWorkspace3_ds_grails_app_views_layouts_main_gsp.run(main.gsp:17)
at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:44)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:197)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:171)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.IllegalArgumentException: Module [__@adhoc-files@__] depends on resource [/images/product/p312roduct/original/Candle_4.jpg] but the file cannot be found
at org.grails.plugin.resource.ResourceTagLib$_closure8.doCall(ResourceTagLib.groovy:463)
at org.grails.plugin.resource.ResourceTagLib.invokeMethod(ResourceTagLib.groovy)
at org.grails.plugin.resource.ResourceTagLib$_closure6.doCall(ResourceTagLib.groovy:387)
... 7 more
The resources plugin expects that the underlying files in modules do not change. Furthermore, any static assets that are being linked to directly by the app (and not through a module or a <g:resource> tag), are considered to be ad-hoc, and are added as modules to the resources context. This allows even these “legacy” assets to be minified, compiled, cached, etc. by the resources plugin.
If you are using the file system to deliver these somewhat dynamic assets of yours, you’re better off excluding them from the resources plugin’s ad-hoc processing. Set the configuration flag grails.resources.adhoc.excludes to exclude whatever directory you are storing these assets in.