grailsasset-pipelinegrails-3.0grails-services

Grails 3 - get asset path in service


I need to get the path of a static resource located in assets/schemas/resource.json in a Grails 3 service.

At the moment it is defined as

private final String SCHEMA = 'grails-app/assets/schemas/resource.json',

which is fine for development environment, but of course not for production (as it would be located in <app_root>/assets/resource.json.

I tried to search how to exploit the Asset Pipeline in my case, but up to now I really have no idea :P

Thanks in advance!


Solution

  • It is covered in the docs. http://bertramdev.github.io/grails-asset-pipeline/guide/usage.html

    In a controller or service, inject the assetResourceLocator and use assetResourceLocator.findAssetForURI()