I have a Java Spring Boot backend application that uses Firebase Admin SDK. inside the init method for FirebaseConfig I have to supply the credentials file for the FirebaseOptions,
@PostConstruct
public void init() throws IOException {
ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
FileInputStream refreshToken = new FileInputStream("src/main/resources/progresee-fa969-firebase-adminsdk-3vip2-d80bf340b7.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(refreshToken))
.setDatabaseUrl(dbUrl)
.build();
FirebaseApp.initializeApp(options);
}
everything works fine when I run locally, but when I build the jar file and upload to the server hosting service(AWS) I get a FileNotFound error -
Caused by: java.io.FileNotFoundException: /progresee-fa969-firebase-adminsdk-3vip2-d80bf340b7.json (No such file or directory)
at java.io.FileInputStream.open0(Native Method) ~[na:1.8.0_222]
at java.io.FileInputStream.open(FileInputStream.java:195) ~[na:1.8.0_222]
at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[na:1.8.0_222]
at java.io.FileInputStream.<init>(FileInputStream.java:93) ~[na:1.8.0_222]
at com.progresee.app.firebase.FirebaseConfig.init(FirebaseConfig.java:55) ~[classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
... 74 common frames omitted
I tried to upload the file to a s3 bucket or firebase and to access it via URL but that way doesn't even work locally.
Thanks in advance, Chen.