5

I am not able to access web-app folder files in Grails 3. I have robots.txt in the web-app folder and in Grails 2 I was able to access it directly at http://localhost:8080/robots.txt. After migrating to Grails 3 I am not able to access it anymore at http://localhost:8080/robots.txt.

How can I make these files accessible again?

doelleri
  • 17,308
  • 5
  • 57
  • 60
naresh
  • 145
  • 11

2 Answers2

6

See https://github.com/grails/grails-core/releases/tag/v3.0.12 and part Location of static resources

In Grails 3 you can store your files under src/main/resources. You can access them by filename preceded with static for example http://localhost:8080/static/robots.txt.

This path can be changed using config option as defined in attached URL

droggo
  • 1,509
  • 9
  • 15
1

I faced a similar problem in Grails 3.3.1. I had the necessity to access a file template to use it with a plugin (excel-export plugin). After reading the documentation, I put the file under src/main/resources. It worked with OK in development mode (grails run-app), but I received an error in production environment (grails war). After a lot of reading, I've found the way to make it work. I've let the file in the same directory (src/main/resources), and then, in my controller:

def template = this.class.classLoader.getResource('myExcelFile.xlsx')
def path = template.file  //will give you the real path to your file

Having the path, you can then open a stream or do what you need to do. In my case, use it whith the plugin:

new WebXlsxExporter(path).with {
  setResponseHeaders(response)
    add(products, withProperties)
    save(response.outputStream)
}