Load different stylesheets when packaging a war file with Grails

冷暖自知 提交于 2019-12-12 02:56:50

问题


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.


回答1:


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.)



来源:https://stackoverflow.com/questions/26109013/load-different-stylesheets-when-packaging-a-war-file-with-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!