GithubHelp home page GithubHelp logo

Comments (3)

GavinC1985 avatar GavinC1985 commented on August 11, 2024 5

Aha okay I figured it out - it was the
InputStream in = Main.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
This should be InputStream in = new FileInputStream(CREDENTIALS_FILE_PATH);
The credentials path being the full path:
private static final String CREDENTIALS_FILE_PATH = "src/main/resources/credentials.json";

Hmm it looks like this reference is stale in a lot of the articles...

InputStream in =Quickstart.class.getResourceAsStream("/credentials.json");

Anyway that fixed it for me :-D

from java-samples.

sableeyed avatar sableeyed commented on August 11, 2024

As long as you add a "/" to CREDENTIALS_FILE_PATH (and assuming credentials is in src/main/java which is where "mkdir -p src/main/java src/main/resources" comes in.

Are you using windows? because the -p switch for mkdir is only present in GNU/Linux Variants.
mkdir --parents src/main/java src/main/resources, which if I am interpreting the man pages correctly, it's kind of like a symbolic link, where your resources files should be visible from src/main/java.

tl;dr, CREDENTIALS_FILE_PATH = "/credentials.json" will suffice on Windows

from java-samples.

erickoledadevrel avatar erickoledadevrel commented on August 11, 2024

Thanks @mlizbeth for the tip, it seems like there is an issue if the class is not in the root package, since the credentials.json is currently being loaded with a relative path. The instructions say to put the class in the root package, but it's less error prone to specify the absolute path. I'll send out a PR.

@GavinC1985 - It looks like you aren't using Gradle as specified in the instructions, and you are setting the source root at /src instead /src/main/java, resulting in incorrect packages like main.java.Main.

from java-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.