I've recently upgraded a grails app to 2.4.3 and in the process upgraded the resources plugin to 1.2.14. I realize the assets plugin is preferred at this point, but I cannot make the switch just yet. I have the following defined in my ApplicationResources.groovy
modules = {
core {
resource url: '/js/main.js', disposition: 'head'
resource url: '/lib/bootstrap/css/bootstrap.css', disposition: 'head'
... more here
}
}
When I run the app, I get the following:
| Error 2015-02-01 23:13:40,005 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /lib/bootstrap/css/bootstrap.css
If you look at the image I've attached, you can see that this file is indeed in the correct place, and this worked with an older version of the resources plugin.
The Grails Resources plugin uses the grails.resources.adhoc.patterns and grails.resources.adhoc.includes values in Config.groovy to determine which resources to process. Perhaps this behavior changed across versions and you need to add the lib directory like so:
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', '/lib/bootstrap/css/*']
grails.resources.adhoc.includes = ['/images/**', '/css/**', '/js/**', '/plugins/**', '/lib/bootstrap/css/**']
I know it is a very old question, but thought my finding would helpful to someone. If we place grails.resources.resourceLocatorEnabled = false in Config.groovy file then it should work. No need to add grails.resources.adhoc property.
Related
I want to use fontawesome plugin in grails.
I have added in build config compile :font-awesome-resources:4.0.3.1 to add plugin.I have added
customBootstrap
{
dependsOn 'font-awesome'
resource url: 'css/bootstrap.css'
resource url: 'js/bootstrap.js' resource url: 'css/bootstrap-fixtaglib.css'
}
in applicationresource.groovy but when i run the application get error
ERROR resource.ResourceProcessor - Unable to load resources Message: No such property: pluginManager for class: org.springframework.web.context.support.XmlWebApplicationContext.Please provide solution.
I am not sure whether this is a configuration issue with migration from earlier grails versions or if font-awesome has not been migrated completely to grails 2.4.x. But I encountered this as well.
As a short (dirty) workaround, you can replace the code that causes the problem directly on the plugin.
File (replace X with your project name):
~/.grails/2.4.2/projects/X/plugins/font-awesome-resources-4.0.3.1/grails-app/conf/FontAwesomePluginResources.groovy
Replace lines 3 and 4 with:
def pluginManager = grails.util.Holders.pluginManager
def lesscssPlugin = pluginManager.getGrailsPlugin('lesscss-resources') || pluginManager.getGrailsPlugin('less-resources')
And give it a go.
The system I maintain is using cached-resources plugin, therefore all of the css/js files are described in Resources.groovy ( stands for my project's name) file.
The usage is normally via *.gsp files, when including resources.
Though, I need to get the list of all files described in there via *.groovy file.
The format of *Resources.groovy file is like this:
modules = {
css {
resource url: 'fileName1.js'
resource url: 'fileName1.js'
...
resource url: 'fileNameN.js'
}
}
How do I get, e.g. "fileName1.js" from service?
Does this work? Given it a quick go in the console for Grails 2.3.4 and it seems to for me, but YMMV:
List urls = grailsApplication.mainContext
.getBean('resourceService') // Instance of [1]
.getModule( 'css' ) // Instance of [2]
.resources // List of [3]
.sourceUrl
ResourceProcessor
ResourceModule
ResourceMeta
Trying to use the Jquery-UI plugin from http://grails.org/plugin/jquery-ui
but apparently the documentations is not correct when discuss using the plugin with resources framework as following the instructions leads to an error:
Error processing GroovyPageView: Error executing tag <r:layoutResources>: No module found with name [jquery-ui]
Apparently the same problem is known around, but was not able to find a solution on the net (example: some discussion here and some other discussions with no solution or hints to a solution).
Did anyone managed to successfully configure jquery-ui in grails with the resource framework?
First you need to install the plugin, so in your BuildConfig.groovy
plugins {
...
compile ":jquery-ui:1.8.24"
...
}
Use grails compile --refresh-dependencies and see if the console output the download of the plugin. If you are using STS, you can go in right click > grails tools > refresh dependencies
After that, you can add <r:require module="jquery-ui"/> before the <r:layoutResources/>
A usefull tip is the change of the jquery ui theme, you can configure this in your ApplicationResources.groovy
modules = {
overrides {
'jquery-theme' {
resource id:'theme', url:'/css/ui/jquery-ui-1.8.21.custom.css'
}
}
}
In this example i have one css located in web-app/css/ui/.
Another tip is that you can force your modules to depend on jquery-ui:
modules = {
mymodule {
dependsOn 'jquery-ui'
resource url: '/js/my.js'
}
}
So if you add the resource mymodule to your GSP, the jquery-ui will be loaded too.
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
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'
}
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}"
}
...
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"/>
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
I am having trouble with the plugin. Everything seemed fine but after running the app in dev env, the page loads up but complains that it can't find the compiled css file. I am using Grails 2.0.1 and lesscss-resources 1.3.0.
Here is what I have in UiResources.groovy:
styling {
defaultBundle 'styling'
resources url: '/less/mainStyles.less', attrs:[rel: "stylesheet/less", type: 'css'], disposition: 'head', bundle: 'bundle_styling'
resources url: '/css/other.css', disposition: 'head'
}
What shows up on the page is this:
< link href="/appName/bundle-bundle_styling_head.css" type="text/css" media="screen, projection" rel="stylesheet" >
Although I can locate this file in the
~/.grails/2.0.1/projects/appName/tomcat/worl/Tomcat/localhost/appName/grails-resources ...
Grails console also complains:
Resources not found: /bundle-bundle_styling_head.css
I have been trying different things to get this to work till no avail. Did I do anything wrong here?
I had a similar problem and found that removing the bundle option fixed the problem. So remove ", bundle: 'bundle_styling'" making the line:
resources url: '/less/mainStyles.less', attrs:[rel: "stylesheet/less", type: 'css'], disposition: 'head'
Hope this works for you too.
Be aware what the docs say currently in the issues section - maybe you are facing one of the bugs:
For the Bundle to work you must have a .css file at the end of the bundle, even if it is just a blank file.
Must specify the default bundle manually as this is calculated based on file extension by default.
I just had a case where I specified this in an inplace plugin (MyPluginApplicationResources.groovy)
resource url:'/less/eip.less', attrs:[rel: "stylesheet/less", type:'css'],defaultBundle: 'eip'
resource url: '/css/dummy.css', defaultBundle: 'eip'
There was no error but also no css rendered by the plugin, so I changed it to:
resource url:[dir: '/less', file : 'eip.less', plugin: 'my-plugin'], attrs:[rel: "stylesheet/less", type:'css'],defaultBundle: 'eip'
resource url: '/css/dummy.css', defaultBundle: 'eip'
This worked for me.
dummy.css : this is an empty css file (see issues) - but I haven't tested if its really needed.