Skip to content
Advertisement

How to read a file from maven resources folder in GCP Cloud Function?

My project uses Maven with the default folder structure and when my Google Cloud Function is trying to read a JSON file from the resources directory (src/main/resources), it fails with:

File Not Found Exception

Below is my code which is standard to read from the classpath resources folder.

Any hints what could be wrong?

JavaScript

Advertisement

Answer

I use a FileReader with BufferedReader in my GCP Cloud Functions:

JavaScript

Using IOUtils from Apache Commons (org.apache.commons.io.IOUtils):

JavaScript

I tried some tests with getResourceAsStream but no success!


Reference:

Advertisement