问题描述
我使用Grails已经快一年了。从现在开始,当我想链接一个CSS或JS文件在GSP中。我做了以下操作:-
我在web-app文件夹下创建了一个新文件(例如资源文件)所有我的文件夹文件(例如,当导入引导程序时,我有一个父文件夹bootstrap在资源下,并且在bootstrap下有css,img和js文件夹和它们的文件)。 然后,要导入一个css文件,我做了以下操作():
blockquote
$ {resource(dir:$ b $'resources / bootstrap / css',file:'bootstrap.min.css')}
type =text / css>
这很好,但是当我尝试在grails 2.2.4中创建一个新项目时,我找不到资源错误(404到浏览器和下面来
错误resource.ResourceMeta - 资源未找到:/resources/bootstrap/css/bootstrap.min.css
ERROR resource.ResourceMeta - 找不到资源:/resources/bootstrap/js/bootstrap.min.js
ERROR resource.ResourceMeta - 找不到资源:/resources/bootstrap/css/bootstrap.min.css
ERROR resource.ResourceMeta - 找不到资源:/resources/bootstrap/js/bootstrap.min.js
当我意识到控制台中的这些错误是来自资源功能,并且一次来自客户端(浏览器)请求的GET。
当查看我看到他们建议使用js和css文件夹。是否有意义的在这两个目录中拆分工具(例如twitter bootstrap)?
)工作解决方案:
假设我们需要同时包含Twitter Bootstrap 3和TinyMce
在我创建的webapp目录下以下目录:
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 / / *这里有很多文件* /
resources / tiny_mce / plugi ns / / *这里有很多文件* /
resources / tiny_mce / themes / / *这里有很多文件* /
resources / tiny_mce / utils / / *这里有很多文件* /
resources / tiny_mce /tiny_mce_popup.js
resources / tiny_mce / tiny_mce_src.js
resources / tiny_mce / tiny_mce.js
然后我在ApplicationResources.groovy中声明我的资源
modules = {
application {
资源url:'js / application.js'
}
jquery {
资源url:'resources / jquery / jquery-2.0.3.min.js'
ootstrap {
dependsOn'jquery'
资源url:'resources / bootstrap / css / bootstrap.min.css'
resource url:'resources /bootstrap/js/bootstrap.min.js'
}
tinymce {
资源网址:'resources / tiny_mce / tiny_mce.js'
}
}
并在Config.groovy中
grails.resources.adhoc.pattern s = ['/ 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中
<!DOCTYPE HTML>
< head>
< g:javascript library =bootstrap/>
< g:javascript library =tinymce/>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge,chrome = 1>
< title>< g:layoutTitle default =Grails/>< / title>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0>
< link rel =快捷方式图标href =$ {resource(dir:'images',file:'favicon.ico')}type =image / x-icon>
< link rel =stylesheethref =$ {resource(dir:'css',file:'main.css')}type =text / css>
< link rel =stylesheethref =$ {resource(dir:'css',file:'mobile.css')}type =text / css>
< r:layoutResources />
< g:layoutHead />
< / head>
< body>
< div id =grailsLogorole =banner>< a href =http://grails.org>< img src =$ {resource(dir:'images' ,file:'grails_logo.png')}alt =Grails/>< / a>< / div>
< div class =footerrole =contentinfo>< / div>
< div id =spinnerclass =spinnerstyle =display:none;>< g:message code =spinner.altdefault =Loading& hellip;/> < / DIV>
< r:layoutResources />
< / body>
< / html>
而在index.gsp中
< HEAD>
...
< script type =text / javascript>
$(function(){
tinymce.init({selector:'textarea'});
});
< / script>
< / head>
< body>
...
< h1>欢迎来到Grails< / h1>
check bootstrap - start
< span class =glyphicon glyphicon-search>< / span>
< button type =buttonclass =btn btn-default btn-lg>
< span class =glyphicon glyphicon-star>< / span> Star
< / button>
check bootstrap - stop
< textarea>您的内容在这里。< / textarea>
...
< / body>
使用上面的,我已经完全运作了JQuery,Bootstrap3和TinyMCE
但是如果一个I在Config.groovy中设置grails.resources.debug = true
我收到了与TinyMce之后动态提取的
grails.resources.adhoc.excludes
资源有关的404错误页面加载。
任何线索?我非常接近找到解决方案,所以我很乐意为您输入
这个测试项目可以从这里下载: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:
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).
Then, to import a css file I did the following (here is documentation for this):
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…"/></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 TinyMCEBut 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 inputThis test project can be downloaded from here: https://docs.google.com/file/d/0B8epX7R4j7jeaVh5OTFiQlV4V0U/edit?usp=sharing
这篇关于资源未找到错误,资源插件如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!