8

groovy grails项目中,我想外部化log4j.properties文件,并且我想创建通用相对路径以使其在LinuxWindows.

为了外部化,我已经删除了log4j = { ... }代码并使用以下代码grails-app/conf/Config.groovy 更新了文件。grails-app/conf/spring/resources.groovy

beans = {
    log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
        targetClass = "org.springframework.util.Log4jConfigurer"
        targetMethod = "initLogging"
        arguments = ["./log4j.properties"]
    }
}

log4j.properties文件位于存在 etc 文件夹的根目录tomcatwebapps, conf,/tomcat/log4j.properties

上面的代码可以在机器上运行,Windows但不能在linux机器上运行。

我尝试了以下方法:

  1. 设置以下内容:

     arguments = ["${System.properties['catalina.home']}/log4j.properties"]
    
  2. 我也尝试将值设置grails-app/conf/Config.groovy

     grailsApplication.config.log4j_path = "${System.properties['catalina.home']}/log4j.properties"
    

并尝试在grails-app/conf/spring/resources.groovy文件中使用它:

 arguments = [grailsApplication.config.log4j_path]

但没有工作。

有人可以告诉我如何设置路径,以便它可以在WindowsLinux.

任何帮助表示赞赏。

4

0 回答 0