在安装Grails war文件期间是否可以运行某种脚本?
例如,在安装过程中,我想将应用程序的Config.groovy文件复制到Tomcat服务器的conf文件夹中。这样,它可以用作外部配置文件(而不必每次手动创建并将其移动到那里)。这样的事情可能吗?
最佳答案
我认为您可以使用BootStrap来做到这一点。当应用程序初始化时,检查您是否在Tomcat(catalina.home prop)中,并且如果文件不存在,请创建。
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()
}
}
}
}
}
关于grails - 在Grails中安装war文件时运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062503/