Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static is not returning any css or js resources in Grails 1.4

I have just created my first Grails 1.4 application, and am having some problems with the new resourse management: the "static handler" is not returning any css or js files, but instead saying:

ERROR resource.ResourceMeta  - Resource not found: /static/plugins/jquery-ui-1.8.15/jquery-ui/themes/ui-lightness/jquery-ui-1.8.15.custom.css
ERROR resource.ResourceMeta  - Resource not found: /static/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.min.js
ERROR resource.ResourceMeta  - Resource not found: /static/plugins/blueprint-1.0.2/css/blueprint/screen.css
ERROR resource.ResourceMeta  - Resource not found: /static/plugins/jquery-ui-1.8.15/jquery-ui/js/jquery-ui-1.8.15.custom.min.js
ERROR resource.ResourceMeta  - Resource not found: /static/css/main.css
ERROR resource.ResourceMeta  - Resource not found: /static/js/application.js

Images are working fine!

As you can see on the below files, I have really scrapped everything off - so I am thinking that I might be missing some general setting somewhere?

The layout file (main.gsp):

<html>
   <head>
      <g:layoutTitle/>
      <r:layoutResources/>

   </head>
   <body>
      <g:layoutBody/>
      <r:layoutResources/>
   </body>
</html>

The page (index.gsp):

<html>
   <head>
      <meta name="layout" content="main"/>
      <r:require modules="jquery-ui, blueprint"/>
      <r:require module="core"/> 
    </head> 
    <body> 
    <div id="form"> 
        <r:img uri="/images/grails_logo.png" width="100" height="50"/>
        Hello World
     </div> 
    </body> 
</html>

The output HTML:

<html>
    <head>
        <script src="/gdw/static/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.min.js" type="text/javascript" ></script>
        <link href="/gdw/static/plugins/jquery-ui-1.8.15/jquery-ui/themes/ui-lightness/jquery-ui-1.8.15.custom.css" type="text/css" rel="stylesheet" media="screen, projection" />
        <script src="/gdw/static/plugins/jquery-ui-1.8.15/jquery-ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript" ></script>
        <link href="/gdw/static/plugins/blueprint-1.0.2/css/blueprint/screen.css" type="text/css" rel="stylesheet" media="screen, projection" />
        <!--[if lt IE 8]><link href="/gdw/static/plugins/blueprint-1.0.2/css/blueprint/ie.css" type="text/css" rel="stylesheet" media="screen,projection" /><![endif]-->
        <link href="/gdw/static/css/main.css" type="text/css" rel="stylesheet" media="screen" />  
   </head>
   <body>
       <div id="form">
            <img src="/gdw/static/images/grails_logo.png" width="100" height="50" />
            Hello World
        </div>
        <script src="/gdw/static/js/application.js" type="text/javascript" ></script>
   </body>
</html>

And my modules (StaticResources.groovy):

modules = {
    core {
        dependsOn 'jquery'
        defaultBundle 'ui'
        resource url:'/css/main.css', attrs:[media:'screen']
        resource url:'/js/application.js'
    }
}

What am I missing? I tried without requiring the jQuery and blueprint but that didn't change the fact that main.css and application.js still was not found - and the files ARE there!

like image 490
Krauw Avatar asked Oct 09 '22 07:10

Krauw


1 Answers

If you're running on windows, then it looks like you've run into this bug in the resources plugin. There are currently a couple of workarounds:

Add defaultBundle false to your module definition

core {
    defaultBundle false

    dependsOn 'jquery'
    defaultBundle 'ui'
    resource url:'/css/main.css', attrs:[media:'screen']
    resource url:'/js/application.js'
}

Alternatively, try adding the following to Config.groovy

grails.resources.debug=true 
like image 175
Dónal Avatar answered Oct 13 '22 11:10

Dónal