How to get absolute path for a grails application

grails

Solution

This will work locally and in the deployed war:

class MyController implements org.springframework.context.ResourceLoaderAware {
  ResourceLoader resourceLoader 
  def download() {
    //org.springframework.core.io.Resource
    def someImage = resourceLoader.getResource("/images/someImage.png").getFile()
  }
}

Found it in a mail user thread.

Problem

I want the user to be able to download a file in my `web-app/images` folder I've built an action like this: ``` def download () { def file = new File (params.filepath) if (file.exists()) { response.setContentType("application/octet-stream") response.setHeader("Content-disposition", "filename=${file.name}") response.outputStream << file.bytes return } } ``` However when I pass in a file path `/images/myimage.jpeg` it is not finding that image. Question How can I get the absolute path where the grails application is deployed so that I can change my code to be like: ``` def file = new File (absolutePath + params.filepath) ``` Note `System.properties['base.dir']` works locally but not when deployed to tomcat.

Original source