9
A
回答
15
您可以創建scripts/_Events.groovy
帶有事件處理程序,用於一旦Grails和插件完成其更改後觸發的'WebXmlEnd'事件。更新與普通搜索XML /通過解析XML更換或通過DOM方法並寫出更新的文件:
import grails.util.Environment
eventWebXmlEnd = { String filename ->
if (Environment.current != Environment.PRODUCTION) {
return
}
String content = webXmlFile.text
// update the XML
content = ...
webXmlFile.withWriter { file -> file << content }
}
0
我從來沒有嘗試過,但它應該可以指定參數在BuildConfig.groovy
依賴於當前的環境。
有一個list of available BuildConfig settings here
編輯
其實,due to this issue,這不是前進的道路:-(也許傳遞特性,如:
grails -Dgrails.config.base.webXml=/path/to/web.xml
是所有的可能?
8
這裏這就是我使用,從傢伙在上death-head.ch
解決方案先安裝模板
grails install-templates
然後自定義web.xml
你會發現在src/templates/war/web.xml
。我選擇了製作一個web_dev.xml
和一個web_prod.xml
並刪除了web.xml
。我希望web_prod.xml
包含一個安全約束塊。反正...
放置在BuildConfig.groovy
如下:
// #########################################################
// ## Can't use environment switching block because BuildConfig doesn't support it.
// ## @url http://jira.grails.org/browse/GRAILS-4260
// ## So use this workaround:
// ## @url http://death-head.ch/blog/2010/09/finally-solved-the-base-authentication-in-grails/
// #########################################################
switch ("${System.getProperty('grails.env')}") {
case "development":
if (new File("/${basedir}/src/templates/war/web_dev.xml").exists()) {
grails.config.base.webXml = "file:${basedir}/src/templates/war/web_dev.xml"
}
break;
default:
if (new File("/${basedir}/src/templates/war/web_prod.xml").exists()) {
grails.config.base.webXml = "file:${basedir}/src/templates/war/web_prod.xml"
}
break;
}
祝你好運!
相關問題
- 1. 適用於不同環境的Jboss-web.xml
- 2. 特定於環境的Grails服務配置
- 3. Grails的定製環境
- 4. Emacs特定於shell的環境變量
- 5. 特定於Python的PATH環境變量?
- 6. 特定於環境的內存泄漏
- 7. anaconda下特定於環境的pip.conf
- 8. 發佈環境特定appsettings.ENV.json只適用於各自的環境
- 9. Grails環境
- 10. 在web.xml中引用環境變量
- 11. 使用Grails環境特定配置的優點
- 12. 定製Grails環境的行爲
- 13. Maven Grails web.xml
- 14. Laravel4種子特定環境
- 15. 與特定語言環境
- 16. Terraform環境特定變量
- 17. Web.config中特定於環境的customSection屬性
- 18. 從特定於語言環境的字符串中獲取NSDecimalNumber?
- 19. springboot中特定於環境的application.properties應用
- 20. Rails 3中特定於環境的路由選擇
- 21. 在VS-2010中創建特定於環境的配置文件
- 22. 在特定於Windows的環境中使用Rcpp包含
- 23. XCode/iOS中特定於語言環境的默認設置
- 24. 不在特定環境中導出conda環境
- 25. RVM,JRuby的設定特定Java環境
- 26. Grails:改變當前環境
- 27. Maven Grails插件環境
- 28. 鏈輪中環境特定變量
- 29. 在特定環境中啓動ipython qtconsole
- 30. 如何設置GAE環境特定的環境變量?
這很好。在Grails 2.2.0中,我從'grails.util.Environment.getCurrent()。getName()'中讀取''{$ System.getProperty('grails.env')}而不是' – Alex 2013-09-23 17:10:11