尝试访问Firebase时NoClassDefFound

时间:2018-06-08 15:46:04

标签: firebase intellij-idea noclassdeffounderror

我正在尝试创建一个在intellij中修改我的firestore数据库的程序。我得到了一个类noclassdeffound错误,我很丢失。根据错误和我读到的内容,我猜我的依赖项中的某个地方,它们引用了BaseGrpcServiceException,我没有将它包含在我的依赖项中,所以我想我应该添加它。但我不知道怎么做(罐子?,库?)或这是否有帮助。任何意见,将不胜感激。这是我的代码:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.cloud.FirestoreClient;


public class serverCode {
    public static void main(String[] args) {
        try {
            FileInputStream serviceAccount =
                    new FileInputStream("./src/serverCodeKey.json");

            FirebaseOptions options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setDatabaseUrl("myDatabaseURL")
                    .build();

            FirebaseApp.initializeApp(options);

            Firestore db = FirestoreClient.getFirestore();
        } catch(FileNotFoundException e) {
            System.out.println("FILE NOT FOUND");
            System.out.println(e.getMessage());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

这些是我的依赖项:

com.google.firebase:firebase-admin:6.2.0
org.slf4j:slf4j-log4j12:1.7.5

这是错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/cloud/grpc/BaseGrpcServiceException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.google.cloud.firestore.FirestoreOptions$FirestoreDefaults.getDefaultRpcFactory(FirestoreOptions.java:142)
    at com.google.cloud.firestore.FirestoreOptions$FirestoreDefaults.getDefaultRpcFactory(FirestoreOptions.java:131)
    at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:278)
    at com.google.cloud.firestore.FirestoreOptions.<init>(FirestoreOptions.java:126)
    at com.google.cloud.firestore.FirestoreOptions$Builder.build(FirestoreOptions.java:115)
    at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:40)
    at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:26)
    at com.google.firebase.cloud.FirestoreClient$FirestoreClientService.<init>(FirestoreClient.java:81)
    at com.google.firebase.cloud.FirestoreClient.getInstance(FirestoreClient.java:71)
    at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:64)
    at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:52)
    at serverCode.main(serverCode.java:26)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.grpc.BaseGrpcServiceException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

0 个答案:

没有答案