Issue
I am developing a simple JavaFx application for a client using Firebase.
This application worked perfectly without JavaFx, however I had to re-create this project to get JavaFx working with it (simply adding dependencies didn't work).
I know this question is a possible duplicate, but I have tried almost all methods suggested before. (linked the ones I tried below)
When using GoogleCredentials, the application throws this error:
java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found
This is the class that has the method: (See the private constructor)
public class DataManage {
private FirebaseOptions options;
private Firestore firestore;
private FirebaseAuth mAuth;
public static DataManage getInstance() {
return Holder.INSTANCE;
}
public void initApp() {
FirebaseApp.initializeApp(options);
}
public UserRecord getUserInfo(String email) {
try {
return mAuth.getUserByEmail(email);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void getUserDataFromDate(String email, Date date) {
try {
//Todo add stuff later
} catch (Exception e) {
e.printStackTrace();
}
}
/// I call the GoogleCredentials.fromStream() method here
private DataManage() {
try {
FileInputStream inputStream = new FileInputStream("service-account.json");
options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(inputStream))
.setDatabaseUrl("https://attendance-349db.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
firestore = FirestoreClient.getFirestore();
mAuth = FirebaseAuth.getInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
private static class Holder {
private static final DataManage INSTANCE = new DataManage();
}
}
This is my maven dependency file: (only including the dependencies and part of build to avoid cluttering)
Dependencies:
<dependencies>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>8.1.0</version>
<exclusions>
<exclusion>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17-ea+11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17-ea+11</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Build:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.indo.attendanceserver/com.indo.attendanceserver.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My modules:
module com.indo.attendanceserver {
requires javafx.controls;
requires javafx.fxml;
requires firebase.admin;
requires google.cloud.firestore;
requires com.google.auth.oauth2;
opens com.indo.attendanceserver to javafx.fxml;
exports com.indo.attendanceserver;
exports com.indo.attendanceserver.scenes.intro;
opens com.indo.attendanceserver.scenes.intro to javafx.fxml;
exports com.indo.attendanceserver.scenes.user;
opens com.indo.attendanceserver.scenes.user to javafx.fxml;
}
Here are the links to suggestions that I've tried but didn't work:
No app-engine files in my project.
Excluding didn't help, tried without excluding too
Any help is greatly appreciated.
Solution
I've managed to fix this issue.
All I had to do was add
requires com.google.auth;
to my module-info.java
file.
The final file looks something like this:
module com.indo.attendanceserver {
requires javafx.controls;
requires javafx.fxml;
requires firebase.admin;
requires google.cloud.firestore;
requires com.google.auth.oauth2;
requires com.google.auth;
opens com.indo.attendanceserver to javafx.fxml;
exports com.indo.attendanceserver;
exports com.indo.attendanceserver.scenes.intro;
opens com.indo.attendanceserver.scenes.intro to javafx.fxml;
exports com.indo.attendanceserver.scenes.user;
opens com.indo.attendanceserver.scenes.user to javafx.fxml;
}
I hope this helps anyone who is looking for an answer.
Answered By - Habba Inoba
Answer Checked By - Gilberto Lyons (JavaFixing Admin)