Carl Jack
Carl Jack

Reputation: 31

java.io.FileNotFoundException: Resource not found: /credentials.json on Java QuickStart for Classroom API

I have implemented the Java QuickStart for the Classroom API and am getting an error message "java.io.FileNotFoundException: Resource not found: /credentials.json" at run-time. I copied my credentials.json file to the Project res directory, but continue to get this error. Any suggestions?

Upvotes: 3

Views: 6666

Answers (4)

j.xavier.atero
j.xavier.atero

Reputation: 604

There are two steps needed to find the resource in Eclipse:

  1. To have the file in the resources folder
    • Create the resource folder (if it does not exist): src/main/resouces
    • Add the credential file to the resource folder: src/main/resouces/credential.json
  2. To have the resources folder in the Source Java Build Path
    • Go to Eclipse Path Source: Project > Properties > Java Build Path > Source (tab)
    • Add resources folder: Add Folder ... (button) > resources (check box) > OK (button)

https://stackoverflow.com/a/46950488/10850340

Upvotes: 1

Stefan
Stefan

Reputation: 25

The name of your file has to be credentials only, if you have credentials.json as the name of your file in your folder you will get this error.

Upvotes: 0

Abdul Samad
Abdul Samad

Reputation: 51

I tried it in a different way than I found on other websites, and it worked for me.

replace below code:

InputStream in = GoogleSheetAPIHandler.class.getClass().getResourceAsStream(CREDENTIALS_FILE_PATH);

With this code:

InputStream in = new FileInputStream(CREDENTIALS_FILE_PATH);

Upvotes: 5

Satheeshkumar
Satheeshkumar

Reputation: 85

You need to import credential.json file into the src/main/resources folder in eclipse. You may be included in the project folder. But you need to import it into eclipse.

  • locate your credentials.json file in the folder.
  • click and drag it
  • drop it in src/main/resource and click ok.
  • After importing into eclipse it should show like the below image.

enter image description here

Upvotes: 1

Related Questions