我在 stackoverflow 上搜索了这个问题,发现了一些类似的引用资料,但没有具体的解决方案......
我使用 Grails 2.4.2 和 twitter-bootstrap:3.2.1 插件,但在运行应用程序期间出现以下错误:
| Error 2014-07-26 11:51:48,592 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-fixtaglib.css
| Error 2014-07-26 11:51:48,668 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap.css
| Error 2014-07-26 11:51:48,725 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-theme.css
| Error 2014-07-26 11:51:48,778 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-alert.js
| Error 2014-07-26 11:51:48,807 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-affix.js
| Error 2014-07-26 11:51:48,837 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-dropdown.js
| Error 2014-07-26 11:51:48,860 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-modal.js
| Error 2014-07-26 11:51:48,888 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-popover.js
| Error 2014-07-26 11:51:48,907 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-scrollspy.js
| Error 2014-07-26 11:51:48,921 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-tab.js
| Error 2014-07-26 11:51:48,934 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-tooltip.js
| Error 2014-07-26 11:51:48,947 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-button.js
| Error 2014-07-26 11:51:48,959 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-carousel.js
| Error 2014-07-26 11:51:48,977 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-collapse.js
| Error 2014-07-26 11:51:48,996 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap-transition.js
| Error 2014-07-26 11:51:49,012 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /assets/bootstrap.less
该插件的重点是简化 Assets 管道并使插件将所有内容放在正确的位置。
我有 BuildConfig.groovy 设置来拉入插件:
...
plugins {
// plugins for the build system only
build ":tomcat:7.0.54"
// plugins for the compile step
compile ":scaffolding:2.1.2"
//compile ':cache:1.1.7'
compile ":asset-pipeline:1.8.11"
compile ":twitter-bootstrap:3.2.1"
// plugins needed at runtime but not for compilation
//runtime ":hibernate4:4.3.5.4" // or ":hibernate:3.6.10.16"
//runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
runtime ":resources:1.2.8"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.7.4"
compile ":less-asset-pipeline:1.7.0"
//compile ":coffee-asset-pipeline:1.7.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
...
据我所知,我的 GSP 设置正确:
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Task Master - Tasks</title>
<r:require module="jquery"/>
<r:require module="bootstrap-js"/>
<r:require module="bootstrap"/>
<r:layoutResources/>
</head>
<body class="container">
<h1>Task Master - Tasks</h1>
<r:layoutResources/>
</body>
</html>
我检查过,正如错误所述,它们不在/assets 下。我看到有些人通过手动复制 Assets 来破解解决方案,但是该插件还有意义吗?要么是我遗漏了一些简单的东西,要么是插件中有错误。有任何想法吗?谢谢。
--瑞安
请您参考如下方法:
在 Grails 2.4 中,asset-pipeline 是向客户端获取静态资源的默认机制。在您的 BuildConfig 中,使用“asset-pipeline”和“resources”(2.4 之前的默认机制)。我不确定这个配置是否真的是您想要的以及它是否有效。
仅包含 Assets 管道的有效配置应该是:
BuildConfig.groovy:
plugins {
compile ":asset-pipeline:1.8.11"
compile ":twitter-bootstrap:3.2.1"
runtime ":jquery:1.11.1"
}
grails-app/views/layouts/main.gsp:
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Task Master - Tasks</title>
<asset:stylesheet href="application.css"/>
</head>
<body class="container">
<h1>Task Master - Tasks</h1>
<asset:javascript src="application.js"/>
</body>
</html>
grals-app/assets/stylesheets/application.css:
/*
*= require bootstrap
*= require_tree .
*/
grals-app/assets/javascript/application.js:
//= require jquery
//= require bootstrap
//= require_tree .
有关详细信息,请参阅 asset-pipeline plugin 的文档以及 twitter-bootstrap 的文档插件。
I checked and they aren't under /assets as the errors state
这是真的,因为您的应用程序中不会复制任何内容,而是资源位于 assets directory 中。引导插件的。 asset-pipeline 插件会扫描每个插件的 asset 文件夹(或出于兼容性目的而扫描 web-app 文件夹)并将其组合起来,因此在生成的 war 中,所有资源都可用。




