当前,我正在使用IntelliJ作为SDK在Java中设置Firebase云Firestore。在Firebase文档中,说需要它是json文件的服务帐户密钥。我使用FileInputStream方法获取此json文件,并且在获取执行程序的文件时没有任何问题,但是当我将其导出为JAR库时,使用该JAR的项目找不到服务帐户密钥。 ,然后它无法与我的Firebase连接。
现在,我能够连接到Firebase,但是我想在我正在执行的库中执行所有该过程。我向您展示获取文件的代码。
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;
}
当我将所有代码导出为JAR文件时,即使将文件保存在资源文件夹中,也找不到该文件并显示FileNotFoundException。我可以在构建gradle文件中做任何事情还是使用等效方法吗?我想将此项目用作其他项目中的libray。