我正在尝试使用来自GitHub的源代码来设置Weceem。它需要一个用于上载目录的物理路径定义,并需要一个似乎用于写入可搜索索引的目录。上载的默认设置是:
weceem.upload.dir = 'file:/var/www/weceem.org/uploads/'
我想使用诸如WEB-INF / resources / uploads之类的相对路径来定义那些路径。我尝试了一种以前用相对路径访问目录的方法:
File uploadDirectory = ApplicationHolder.application.parentContext.getResource("WEB-INF/resources/uploads").file
def absoluteUploadDirectory = uploadDirectory.absolutePath
weceem.upload.dir = 'file:'+absoluteUploadDirectory
但是,ApplicationHolder.application下的“parentContext”为NULL。谁能为此提供解决方案,让我使用相对路径?
最佳答案
查看您应该拥有的Config.groovy(也许已注释)
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts
// "classpath:${appName}-config.properties", "classpath:${appName}-config.groovy",
grails.config.locations = [
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy"
]
在部署服务器中创建Conig文件
"${userHome}/.grails/${appName}-config.properties"
并在该配置文件中定义您的 Prop (甚至不是相对路径)。
关于grails - 如何导出Config.groovy中相对目录的物理路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10629151/