Grails: Locate file on web-app on production

739 Views Asked by At

i have a file locate in web-app in my grails project.. in the config file for some apns plugin in put the config as the following

    environments {
    development {
        apns {
            pathToCertificate = "web-app/apns-dev.p12"
            password = "password"
            environment = "sandbox"
        }
    }
    test {
        apns {
            pathToCertificate = "web-app/apns-dev.p12"
            password = "password"
            environment = "sandbox"
        }
    }

    production {
        apns {
            pathToCertificate = "apns-prod.p12"
            password = "password"
            environment = "production"
        }
    }
}

the reason i put the p12 of production without "web-app" is because i've noticed that the file located on production under the root directrly but it give me fileNotFoundException.. so how can i locate it?

2

There are 2 best solutions below

1
On BEST ANSWER

The apns plugin page states

If you don't have access to your server's file system, you can also replace pathToCertificate by certificateResourcePath and set it to the path of your certificate, relative to src/java. So for example, if your certificate is in src/java/mycert.p12, you can set certificateResourcePath=mycert.p12.

This is probably your best bet, allowing you to use paths relative to src/java rather than absolute paths.

1
On

Here's a (slighty hacky) way to get the file's absolute path:

First, put the files on the classpath somewhere (e.g. a "resources" directory inside the conf directory). Then, change your pathToCertificate line to:

pathToCertificate = ApplicationHolder.application.parentContext.getResource("classpath:resources/apns-dev.p12").file.absolutePath

which should resolve to the absolute path for that file on your file system.