2014-03-17 1 views
0

개인 Grails 플러그인 mySearch를 사용하는 기본 grails 애플리케이션이 있습니다. 플러그인 검색에는 Search \ web-app \ filters.json에 파일이 있습니다. ressource 파일에 액세스 할 수 있습니다 :Private Grails Plugin web-app에서 리소스에 액세스

def ressource = new File(org.codehaus.groovy.grails.plugins.GrailsPluginUtils.getPluginDirForName('mySearch')?.file?.absolutePath 
+"/web-app/filters.json").text 

하지만 응용 프로그램이 tomcat7에 배치 될 때 작동하지 않는 응용 프로그램을 실행 응용 프로그램과 함께 실행

.

I'have는

pluginManager.getGrailsPlugin('mySearch')를 사용하여 시도하지만 자원의 obsolute 경로에 액세스 할 수 없습니다.

+0

다음을 붙이는 시도, 당신이 말한 만 있으면 시스템 속성 집합 : (grails.util.Environment.warDeployed은 System.getProperty ('카탈 .home ') +'/ webapps/myAppName/WEB-INF/: '') –

+0

전쟁이 폭발하지 않으면 작동하지 않습니다. –

+0

알아두면 좋을 것. 그 점을 지적 해 주셔서 감사합니다. –

답변

0

많은 문제를 해결 한 후에이 해결 방법을 발견했습니다. 이 더러워 보이지만 나는 다른 어떤 짧고 달콤한 발견되지 않았다

// work only for a plugin installed in app deployed from a war. 
String getRessourceFile(String relativePath) throws FileNotFoundException{ 

    def pluginDir = pluginManager.getGrailsPlugin('MyPlugin')?.getPluginPath() 
    def pluginFileSystemName = pluginManager.getGrailsPlugin('MyPlugin')?.getFileSystemName() 

    def basedir = grailsApplication.parentContext.getResource("/")?.file 
    if(basedir.toString().endsWith("web-app")){ 
     basedir = basedir.parent 
    } 

    ressourcefile = "$basedir$pluginDir/$relativePath" 
    ressource = new File(ressourcefile)?.text 
}