문제

I have a main grails application that use a private Grails plugin mySearch. the plugin Search has a file in Search\web-app\filters.json.

when the application is run with run-app : the ressource file can be accessed with :

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

but It doesn't work when the app is deployed in tomcat7.

I'have tried using pluginManager.getGrailsPlugin('mySearch')

but I can't access the obsolute path of the resource.

도움이 되었습니까?

해결책

After many attempts to resolve it, I found this workaround. It looks messy but I didn't found anything else shorter and sweeter :

// 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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top