Currently I am setting up a Firebase cloud Firestore in java, using IntelliJ as SDK. In the Firebase documentation is said that it is needed the Service Account Key which is a json file. I used the method FileInputStream to obtain this json file, and I do not have any problem when I am getting that file executing the program, but when I export this as a JAR library the project which uses that JAR does not find the Service Account Key, and then it can not connect with my firebase.
Now, I am able to connect to firebase but I want to do all that process on a Library that I am doing. I show you the code that is getting my file.
public InputStream obtainInputStream(String pathFile) throws ReadFileException {
InputStream inputStream;
try {
// Create File Input Stream
inputStream = new FileInputStream(pathFile);
} catch (FileNotFoundException e) {
// Get Input Stream
inputStream = getClass().getResourceAsStream(pathFile);
// Check if File Exists
if(inputStream == null) {
throw new ReadFileException(String.format("Error Find File %s", pathFile));
}
}
return inputStream;
}
When I export all my code as a JAR file it does not found the file and show a FileNotFoundException, even when I save the file in the resources folder. Could I do anything in the build gradle file or use an equivalent method? I want to use this project as a Libray in other project.