Using Firebase Admin in a Java desktop application (using Eclipse)

1.9k views Asked by At

I want to use firebase admin in my java application. On the website it says I can add it via gradle or maven. But I don't want to do that. Instead I downloaded the jar file from maven central repository website and added it as a library to my project. I added the code as stated on the firebase guides section and run the application and I get the following output;

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
    at error.myclass.main(myclass.java:17)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

So I tried adding libraries to fix the problem, and every time I run the application I just got another error. These are the libraries I have currently added:

com.google.guava_1.6.0.jar
firebase-admin-4.0.3.jar
google-api-client-1.4.1-beta.jar
google-api-client-gson-1.22.0.jar
google-api-java-client-ext.jar
google-http-client-1.16.0-rc.jar
java-json.jar

Now the only error I get is this:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.api.client.json.gson.GsonFactory.getDefaultInstance()Lcom/google/api/client/json/gson/GsonFactory;
    at com.google.firebase.FirebaseOptions$Builder.setServiceAccount(FirebaseOptions.java:76)
    at MyClass.cool.main(cool.java:18)

I have correctly added all of the libraries so I do not understand why this is not working. So my question is how do I successfully add firebase admin to a java project in eclipse without using gradle or maven.

2

There are 2 answers

0
AudioBubble On BEST ANSWER

I ended up learning how to use Maven which is actually simple when you understand how to set up the project correctly and access the pom.xml file. When I exported the project (with the libraries) all of the necessary jars required was in a folder which I have linked on dropbox.

Link: Dropbox - Firebase Admin Jars (August 2017)

Names of Libraries:

  • commons-codec-1.3.jar
  • commons-logging-1.1.1.jar
  • firebase-admin-5.2.0.jar
  • google-api-client-1.22.0.jar
  • google-api-client-gson-1.22.0.jar
  • google-http-client-1.22.0.jar
  • google-http-client-gson-1.22.0.jar
  • google-http-client-jackson2-1.22.0.jar
  • google-oauth-client-1.22.0.jar
  • gson-2.1.jar
  • guava-20.0.jar
  • httpclient-4.0.1.jar
  • httpcore-4.0.1.jar
  • jackson-core-2.1.3.jar
  • json-20160810.jar
  • jsr305-1.3.9.jar

Note that the files linked are unlikely to be updated, so I would recommend using Maven which should download all of the correct libraries based on the version number in your pom.xml file.

0
Ringo Ame On

In my case, JSON-java-1.4.jar seems to work instead of java-json.jar. You can git clone from JSON-java in GitHub.