我正在处理一个非常奇怪的问题。
我有一个在 IntelliJ 上开发的代码,它尝试从 FireStore DB 中删除文档。
当我在 IntelliJ 中运行 main() 时,没有问题。
但是当我创建该项目的 JAR 并将该 jar 作为“java -jar xxxxx.jar”运行时,出现以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
at com.google.api.gax.retrying.BasicRetryingFuture.<init>(BasicRetryingFuture.java:77)
at com.google.api.gax.retrying.CallbackChainRetryingFuture.<init>(CallbackChainRetryingFuture.java:62)
at com.google.api.gax.retrying.ScheduledRetryingExecutor.createFuture(ScheduledRetryingExecutor.java:84)
at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:61)
at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
at com.google.cloud.firestore.FirestoreImpl.sendRequest(FirestoreImpl.java:327)
at com.google.cloud.firestore.UpdateBuilder.commit(UpdateBuilder.java:608)
at com.google.cloud.firestore.WriteBatch.commit(WriteBatch.java:41)
at com.google.cloud.firestore.DocumentReference.delete(DocumentReference.java:335)
at main.main(main.java:26)
我在我的项目中使用 Gradle 并进行以下构建:
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.firebase:firebase-admin:5.10.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
我正在编写用于删除文档的代码:
FileInputStream serviceAccount = new FileInputStream("./ServiceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).build();
FirebaseApp.initializeApp(options);
Firestore db ;
CollectionReference to_be_Deleted ;
db = FirestoreClient.getFirestore();
ApiFuture<WriteResult> writeResult = db.collection("XXXXXX").document("WW4ovZ5amD56pxjd5NwY").delete();
System.out.println("Update time : " + writeResult.get().getUpdateTime());
我真的需要有关这个问题的帮助。我希望有人能告诉我我的错误。
谢谢大家。
最佳答案
完成以下操作后,它现在对我有用。在 IntelliJ 中,我执行了文件> 使缓存/重新启动。然后我重建了 .jar 文件并成功运行。
当我第二次遇到这个问题时,我还从头开始删除并重建了我的 .jar。
关于java - 使用 JAR 从 FIRESTORE DB 删除文档失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50061966/