如何从Config.groovy中派生相对目录的物理路径? [英] How do I derive physical path of a relative directory inside Config.groovy?
问题描述
我正在尝试使用GitHub的源代码设置Weceem。它需要上传目录的物理路径定义,并且目录似乎用于编写可搜索的索引。上传的默认设置为:
weceem.upload.dir ='file:/var/www/weceem.org/uploads /'
我想要定义那些使用相对路径的文件,例如WEB-INF / resources / uploads。我尝试了一种以前用于访问相对路径目录的方法:
文件uploadDirectory = ApplicationHolder.application.parentContext。 getResource(WEB-INF / resources / uploads)。文件
def absoluteUploadDirectory = uploadDirectory.absolutePath
weceem.upload.dir ='file:'+ absoluteUploadDirectory
然而,ApplicationHolder.application下的'parentContext'是NULL。任何人都可以提供一个解决方案,这将允许我使用相对路径?
看看你应该有的Config.groovy (可能是评论)
//搜索配置文件的位置被合并到主配置中
/ / config文件可以是Java属性文件或ConfigSlurper脚本
//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
并在该配置文件中定义您的道具(即使不是相对路径)。
I am trying to set up Weceem using the source from GitHub. It requires a physical path definition for the uploads directory, and for a directory for appears to be used for writing searchable indexes. The default setting for uploads is:
weceem.upload.dir = 'file:/var/www/weceem.org/uploads/'
I would like to define those using relative paths like WEB-INF/resources/uploads. I tried a methodology I have used previously for accessing directories with relative path like this:
File uploadDirectory = ApplicationHolder.application.parentContext.getResource("WEB-INF/resources/uploads").file
def absoluteUploadDirectory = uploadDirectory.absolutePath
weceem.upload.dir = 'file:'+absoluteUploadDirectory
However, 'parentContext' under ApplicationHolder.application is NULL. Can anyone offer a solution to this that would allow me to use relative paths?
look at your Config.groovy you should have (maybe it is commented)
// 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"
]
Create Conig file in deployment server
"${userHome}/.grails/${appName}-config.properties"
And define your prop (even not relative path) in that config file.
这篇关于如何从Config.groovy中派生相对目录的物理路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!