2017-07-25 51 views
-2

我想用java將條目插入我的Firebase數據庫(java不在android環境中)。這甚至有可能嗎?如何製作java後端Firebase數據庫連接

如果可以請你幫我弄清楚,爲什麼我得到這個錯誤:在eclipse

Exception in thread "main" java.lang.NoSuchMethodError: com.google.firebase.FirebaseOptions$Builder.setCredential(Lcom/google/firebase/auth/FirebaseCredential;)Lcom/google/firebase/FirebaseOptions$Builder;

出現該問題在`setCredential線以下的在我的Maven項目?

try { 
     FileInputStream serviceAccount = new FileInputStream(file); 
     FirebaseOptions options = new FirebaseOptions.Builder() 
       .setCredential(FirebaseCredentials.fromCertificate(serviceAccount)) 
       .setDatabaseUrl(url) 
       .build(); 
     FirebaseApp.initializeApp(options); 
    } catch (FileNotFoundException e) { 
     System.out.println("ERROR: invalid service account credentials. See README."); 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    // Shared Database reference 
    DatabaseReference database = FirebaseDatabase.getInstance().getReference(); 

回答

0

從錯誤消息看來,您似乎包含錯誤的SDK,可能是Android平臺的SDK。確保您按照Firebase documentation on including the Admin SDK中的說明操作。從那裏:

The Firebase Admin Java SDK is published to the Maven central repository. To install the library, declare it as a dependency in your build.gradle file:

dependencies { 
    compile 'com.google.firebase:firebase-admin:5.2.0' 
} 

If you use Maven to build your application, you can add the following dependency to your pom.xml :

<dependency> 
    <groupId>com.google.firebase</groupId> 
    <artifactId>firebase-admin</artifactId> 
    <version>5.2.0</version> 
</dependency> 
+0

這裏是我當前的pom.xml: <依賴性> \t \t \t 的JUnit \t \t 的JUnit \t \t 4.12 \t \t \t com.google.firebase \t 火力管理員 \t 5.2.0 \t

+0

我正在使用的Eclipse Maven項目試圖建立一個後端代碼將在服務器上運行,以將數據上傳到我的Firebase數據庫以供我的應用程序讀取。我不確定我需要在maven中編譯「compile」com.google.firebase:firebase-admin:5.2.0'「。 –