找不到资源错误以及资源插件怎么样 [英] Resource not found Error and what about resources plugin

查看:18
本文介绍了找不到资源错误以及资源插件怎么样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 grails 快一年了.从现在开始,当我想在 gsp 中链接 css 或 js 文件时.我做了以下事情:

  1. 我在 web-app 文件夹下创建了一个新文件(例如资源文件),并将我所有的文件夹文件放在那里(例如,在导入引导程序时,我在资源下有一个父文件夹引导程序,在引导程序下有 css、img 和 js 文件夹及其文件).

  2. 然后,为了导入一个 css 文件,我执行了以下操作(here是用于此的文档):

<块引用>

这很好用,但是当我尝试在 grails 2.2.4 中创建一个新项目时,我遇到了一个 Resource not found 错误(浏览器为 404,控制台为以下错误).

ERROR resource.ResourceMeta - 找不到资源:/resources/bootstrap/css/bootstrap.min.css错误资源.ResourceMeta - 找不到资源:/resources/bootstrap/js/bootstrap.min.js错误资源.ResourceMeta - 找不到资源:/resources/bootstrap/css/bootstrap.min.css错误资源.ResourceMeta - 找不到资源:/resources/bootstrap/js/bootstrap.min.js

我意识到控制台中的这些错误一次来自资源函数,一次来自客户端(浏览器)请求的 GET.

在查看 resources plugin 时,我看到他们建议使用 js 和 css 文件夹.在这两个目录中拆分工具(例如 twitter bootstrap)有意义吗?

解决方案

ok 我相信我有一个(半)可行的解决方案:

假设我们需要同时包含 Twitter Bootstrap 3 和 TinyMce

在 webapp 目录下,我创建了以下目录:

resources/bootstrap/资源/引导程序/CSS/资源/bootstrap/css/bootstrap.min.css资源/引导程序/字体/资源/引导/字体/glyphicons-halflings-regular.eot资源/引导/字体/glyphicons-halflings-regular.svg资源/引导/字体/glyphicons-halflings-regular.ttf资源/引导/字体/glyphicons-halflings-regular.woff资源/引导程序/js/资源/bootstrap/js/bootstrap.min.js资源/jQuery/资源/jquery/jquery-2.0.3.min.js资源/tiny_mce/resources/tiny_mce/langs//*这里有很多文件*/resources/tiny_mce/plugins//*这里有很多文件*/resources/tiny_mce/themes//*这里有很多文件*/resources/tiny_mce/utils//*这里有很多文件*/资源/tiny_mce/tiny_mce_popup.js资源/tiny_mce/tiny_mce_src.js资源/tiny_mce/tiny_mce.js

然后我在 ApplicationResources.groovy 中声明我的资源

modules = {应用 {资源网址:'js/application.js'}jQuery {资源网址:'resources/jquery/jquery-2.0.3.min.js'}引导{取决于'jquery'资源网址:'resources/bootstrap/css/bootstrap.min.css'资源网址:'resources/bootstrap/js/bootstrap.min.js'}微小的{资源网址:'resources/tiny_mce/tiny_mce.js'}}

在 Config.groovy 中

grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']/*这里没有变化*/grails.resources.adhoc.excludes = ['/**/langs/**/*.*', '/**/themes/**/*.*']/* 允许来自 tiny_mce.js 的一些 Ajax 调用到相关资源*/grails.resources.debug=true/*这就是我称我的解决方案为 SEMI 工作的原因.如果将 grails.resources.debug 设置为 false,TinyMce 将不起作用,因为上述排除项未激活,并且我收到 404 错误*/

然后,在 main.gsp

<头><g:javascript library="application"/><g:javascript library="bootstrap"/><g:javascript library="tinymce"/><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title><g:layoutTitle default="Grails"/></title><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon"><link rel="apple-touch-icon" href="${resource(dir: 'images', file: 'apple-touch-icon.png')}"><link rel="apple-touch-icon" size="114x114" href="${resource(dir: 'images', file: 'apple-touch-icon-retina.png')}"><link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css"><link rel="stylesheet" href="${resource(dir: 'css', file: 'mobile.css')}" type="text/css"><r:layoutResources/><g:layoutHead/><身体><div id="grailsLogo" role="banner"><a href="http://grails.org"><img src="${resource(dir: 'images', file: 'grails_logo.png')}" alt="Grails"/></a></div><g:layoutBody/><div class="footer" role="contentinfo"></div><div id="spinner" class="spinner" style="display:none;"><g:message code="spinner.alt" default="Loading&hellip;"/></div><r:layoutResources/>

在 index.gsp 中

...<script type="text/javascript">$(函数(){tinymce.init({selector:'textarea'});});<身体>...<h1>欢迎使用 Grails</h1>检查引导程序 - 启动<span class="glyphicon glyphicon-search"></span><button type="button" class="btn btn-default btn-lg"><span class="glyphicon glyphicon-star"></span>星星检查引导程序 - 停止<textarea>您的内容在这里.</textarea>...

使用上面的,我有完全可操作的 JQuery、Bootstrap3 和 TinyMCE但是如果我在 Config.groovy 中设置了

grails.resources.debug=true

我收到与 TinyMce 在页面加载后动态获取的 grails.resources.adhoc.excludes 资源相关的 404 错误.

有什么线索吗?我真的很接近找到解决方案所以我很高兴得到你的意见这个测试项目可以从这里下载:https://docs.google.com/file/d/0B8epX7R4j7jeaVh5OTFiQlV4V0U/edit?usp=sharing

I am using grails for almost a year. Since now when I wanna link a css or js file in a gsp. I did the following:

  1. I created a new file (eg the resources file) under web-app folder and I put there all my files of folders (eg when importing bootstrap I had a parent folder bootstrap under resources and under bootstrap there were css, img and js folders with their files).

  2. Then, to import a css file I did the following (here is documentation for this):

<link rel="stylesheet" href="${resource(dir: 'resources/bootstrap/css', file: 'bootstrap.min.css')}" type="text/css">

<script src="${resource(dir: 'resources/bootstrap/js', file: 'bootstrap.min.js')}"></script>

This worked great, but when I tried to create a new Project in grails 2.2.4 I had a Resource not found Error (404 to browser and the following to console).

ERROR resource.ResourceMeta  - Resource not found: /resources/bootstrap/css/bootstrap.min.css
ERROR resource.ResourceMeta  - Resource not found: /resources/bootstrap/js/bootstrap.min.js
ERROR resource.ResourceMeta  - Resource not found: /resources/bootstrap/css/bootstrap.min.css
ERROR resource.ResourceMeta  - Resource not found: /resources/bootstrap/js/bootstrap.min.js

As I realized these Errors in console were once from the resources function and once from the GET that client(browser) requested.

When looking at resources plugin I see that they suggest using the js and css folders. Is that meaningful to split a tool (eg twitter bootstrap) in these two directories?

解决方案

ok I believe I have a (semi) working solution:

Suppose we need to include both Twitter Bootstrap 3 and TinyMce

Under webapp directory I create the following directories:

resources/bootstrap/
resources/bootstrap/css/
resources/bootstrap/css/bootstrap.min.css
resources/bootstrap/fonts/
resources/bootstrap/fonts/glyphicons-halflings-regular.eot
resources/bootstrap/fonts/glyphicons-halflings-regular.svg
resources/bootstrap/fonts/glyphicons-halflings-regular.ttf
resources/bootstrap/fonts/glyphicons-halflings-regular.woff
resources/bootstrap/js/
resources/bootstrap/js/bootstrap.min.js
resources/jquery/
resources/jquery/jquery-2.0.3.min.js
resources/tiny_mce/
resources/tiny_mce/langs/ /*many files here*/
resources/tiny_mce/plugins/ /*many files here*/
resources/tiny_mce/themes/ /*many files here*/
resources/tiny_mce/utils/ /*many files here*/
resources/tiny_mce/tiny_mce_popup.js
resources/tiny_mce/tiny_mce_src.js
resources/tiny_mce/tiny_mce.js

Then I declare my resources in ApplicationResources.groovy

modules = {
    application {
        resource url:'js/application.js'
    }

    jquery {
        resource url:'resources/jquery/jquery-2.0.3.min.js'
    }

    bootstrap {
       dependsOn 'jquery'
       resource url:'resources/bootstrap/css/bootstrap.min.css'
       resource url:'resources/bootstrap/js/bootstrap.min.js'
    }

    tinymce {
        resource url:'resources/tiny_mce/tiny_mce.js'
    }
}

And in Config.groovy

grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']   /*no changes here*/
grails.resources.adhoc.excludes = ['/**/langs/**/*.*', '/**/themes/**/*.*']  /*to permit some Ajax calls from tiny_mce.js to relevant resources*/
grails.resources.debug=true 
/* 
this is why I call my solution SEMI working. 
If set grails.resources.debug to false, TinyMce is NOT working because the above excludes are not active, and I receive 404 errors
*/

Then, in main.gsp

<!DOCTYPE html>
    <head>
        <g:javascript library="application"/>
        <g:javascript library="bootstrap"/>
        <g:javascript library="tinymce"/>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title><g:layoutTitle default="Grails"/></title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon">
        <link rel="apple-touch-icon" href="${resource(dir: 'images', file: 'apple-touch-icon.png')}">
        <link rel="apple-touch-icon" sizes="114x114" href="${resource(dir: 'images', file: 'apple-touch-icon-retina.png')}">
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'mobile.css')}" type="text/css">

        <r:layoutResources />
        <g:layoutHead/>
    </head>
    <body>
        <div id="grailsLogo" role="banner"><a href="http://grails.org"><img src="${resource(dir: 'images', file: 'grails_logo.png')}" alt="Grails"/></a></div>
        <g:layoutBody/>
        <div class="footer" role="contentinfo"></div>
        <div id="spinner" class="spinner" style="display:none;"><g:message code="spinner.alt" default="Loading&hellip;"/></div>

        <r:layoutResources />
    </body>
</html>

And in index.gsp

<head>
...
<script type="text/javascript">
$(function() {
    tinymce.init({selector:'textarea'});
});   
</script>
</head>
<body>
...
<h1>Welcome to Grails</h1>
check bootstrap - start
    <span class="glyphicon glyphicon-search"></span>
    <button type="button" class="btn btn-default btn-lg">
     <span class="glyphicon glyphicon-star"></span> Star
    </button>
check bootstrap - stop

<textarea>Your content here.</textarea>
...
</body> 

Using the above, I have fully operational JQuery, Bootstrap3 and TinyMCE But if a I set in Config.groovy

grails.resources.debug=true 

I am receiving 404-errors related to the grails.resources.adhoc.excludes resources that TinyMce dynamically fetches after page load.

Any clues? I am really close to find the solution so I will glad to get your input This test project can be downloaded from here: https://docs.google.com/file/d/0B8epX7R4j7jeaVh5OTFiQlV4V0U/edit?usp=sharing

这篇关于找不到资源错误以及资源插件怎么样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆