【问题标题】:Run script while installing war file in Grails在 Grails 中安装 war 文件时运行脚本
【发布时间】:2013-04-17 14:16:47
【问题描述】:

在安装 Grails 战争文件期间是否可以运行某种脚本?

例如,我想在安装过程中将我的应用程序的 Config.groovy 文件复制到我们的 Tomcat 服务器的 conf 文件夹中。通过这种方式,它可以用作外部配置文件(而不必每次都手动创建并将其移动到那里)。这样的事情可能吗?

【问题讨论】:

    标签: grails installation war


    【解决方案1】:

    我认为您可以使用 BootStrap 来做到这一点。当你的应用初始化时,检查你是否在 Tomcat 中(catalina.home 属性),如果文件不存在,则创建。

    class BootStrap {
      def init = {
        if(grails.util.Environment.warDeployed) {
           String homeFolder = System.getProperty('catalina.home')
           if(homeFolder) {
             File externalConfigFile = new File("$homeFolder/conf/MyAppConfig.groovy")
             if(!externalConfigFile.exists()) {
               externalConfigFile.createNewFile()
             }
           }
        }
      }
    }
    

    【讨论】:

    • 工作得很好。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2018-05-28
    • 2016-11-16
    相关资源
    最近更新 更多