Inside a grails application, I need to upload a file under web-app/js, add a prefix, and put it in S3. I'm having trouble figuring out how to read the js file in a way that will work in development (/web-app/js) and production (/js). I'm d开发者_运维问答oing this from inside a domain object.
In your controllers, you can call :
def jsFolder = grailsAttributes.getApplicationContext().getResource("js/").getFile()
and then proceed with jsFolder
.
To determine the base directory of a running Grails application, use
String dir = applicationContent.getResource("/").getFile()
Getting the js path from a service is a little bit tricky:
You need to implement the ApplicationContextAware
interface like this :
class MyService implements ApplicationContextAware {
ApplicationContext applicationContext
However, calling this code from a domain class is not a good idea (see this thread for some explanations) and I am not even sure if it's possible except from getting paths from manual configurations
Hope it helps.
精彩评论