使用Grails打包war文件时加载不同的样式表 [英] Load different stylesheets when packaging a war file with Grails
问题描述
我想为不同品牌的Grails应用程序打包。在生成war文件的同时,我想传递一些引用某个品牌的自定义参数,并通过为品牌加载样式表来设置应用程序的样式。
我在线阅读并且我发现一种方法是使用maven。我尝试过使用maven,但在初始编译应用程序时,我被卡住了。错误是:
无法执行目标org.grails:grails-maven-plugin:2.2.1:maven-compile $ b项目foreAction上的$ b(default-maven-compile):Forked Grails虚拟机退出时出错。
我坚持要采取什么方法。我搜索了上述错误,并尝试了不同的解决方案,但似乎没有任何工作。
如果没有使用Maven有不同的方式,我愿意尝试一下。 / p>
您可以使用 scripts / _Events.groovy
并取代合适的CSS /资产。 文档解释了如何挂入生成事件。
$ b $ scripts / _Events.groovy
中的代码可能如下所示:
//这是在临时目录准备好之后但打包之前调用的。
eventCreateWarStart = {name,stagingDir - >
//将您的代码放在此处,将您的资源复制到暂存目录中的相应位置。
Ant.copy(
file:System.getProperty('somePassedInFile'),
toFile:$ {stagingDir} /assets/stylesheets/whatever.css,
overwrite: true
)
}
然后你可以像这样从 grails prod war
传入源文件的值:
grails prod war -DsomePassedInFile = / path / to / file.css
希望这至少可以帮助您了解如何实现这一目标。 (全部写下我的头顶,所以要小心输入错误等)。
I want to package a Grails application for different brands. While generating a war file, I want to pass some custom parameter that refers to a certain brand and styles the application by loading the stylesheet for the brand.
I read online and one approach I found was with maven. I tried working with maven but I am stuck while initially compiling the application. The error is
Failed to execute goal org.grails:grails-maven-plugin:2.2.1:maven-compile
(default-maven-compile) on project foreAction: Forked Grails VM exited with error.
I am stuck as to what approach to take now. I searched for the above error and tried different solutions but nothing seems to work.
If there is a different way without using Maven I am willing to give it a shot.
You could always hook into the events using scripts/_Events.groovy
and replace the appropraite CSS/assets. The documentation explains how to hook into build events.
Your code inside scripts/_Events.groovy
might look something like this:
// This is called after the staging dir is prepared but before the war is packaged.
eventCreateWarStart = { name, stagingDir ->
// place your code here that copies your resources to the appropriate location in the staging directory.
Ant.copy(
file: System.getProperty('somePassedInFile'),
toFile: "${stagingDir}/assets/stylesheets/whatever.css",
overwrite: true
)
}
Then you can pass in the value of the source file from grails prod war
like this:
grails prod war -DsomePassedInFile=/path/to/file.css
Hope this helps at least give you an idea of how you can accomplish this. (All written off the top of my head so beware of typos etc.)
这篇关于使用Grails打包war文件时加载不同的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!