Domanda

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.

È stato utile?

Soluzione

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
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top