【发布时间】:2022-01-16 08:11:49
【问题描述】:
我正在使用 Firebase 为客户端开发一个简单的 JavaFx 应用程序。
这个应用程序在没有 JavaFx 的情况下可以完美运行,但是我必须重新创建这个项目才能让 JavaFx 使用它(简单地添加依赖项不起作用)。
我知道这个问题可能是重复的,但我已经尝试了几乎所有之前建议的方法。 (链接了我在下面尝试过的)
使用 GoogleCredentials 时,应用程序会抛出此错误:
java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found
这是具有方法的类:(参见私有构造函数)
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();
}
}
这是我的 maven 依赖文件:(只包括依赖和部分构建以避免混乱)
依赖关系:
<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>
<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>
我的模块:
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;
}
以下是我尝试过但无效的建议的链接:
No app-engine files in my project.
Excluding didn't help, tried without excluding too
非常感谢任何帮助。
【问题讨论】:
标签: java firebase maven javafx