静态不会返回Grails 1.4中的任何css或js资源

时间:2011-12-07 14:30:05

标签: grails resources static

我刚刚创建了我的第一个Grails 1.4应用程序,并且在新的资源管理方面遇到了一些问题:“静态处理程序”没有返回任何css或js文件,而是说:

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

图片工作正常!

正如你在下面的文件中看到的那样,我真的已经废弃了所有东西 - 所以我想我可能会遗漏某些常规设置?

布局文件(main.gsp):

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

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

页面(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>

输出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>

我的模块(StaticResources.groovy):

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

我错过了什么?我试过没有要求jQuery和蓝图,但这并没有改变仍然没有找到main.css和application.js的事实 - 文件就在那里!

1 个答案:

答案 0 :(得分:4)

如果您在Windows上运行,那么您似乎在资源插件中遇到了this bug。目前有几种解决方法:

defaultBundle false添加到模块定义

core {
    defaultBundle false

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

或者,尝试将以下内容添加到Config.groovy

grails.resources.debug=true