1

Recently wrote a Maven Netbeans program that writes to firebase. It all works perfectly when I run it in the Netbeans IDE but when I build it and try to run it I get this error:

C:\Users\TOM\.m2\repository\com\FUJCode\climate2.0\1.0-SNAPSHOT>java -jar climate2.0-1.0-SNAPSHOT.jar
 Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
    at Climate.main(Climate.java:94)
    Caused by: java.lang.ClassNotFoundException: 
    com.google.firebase.FirebaseOptions$Builder
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

I'm not sure why this is happening.

My code links to a json file here:

serviceAccount = new FileInputStream("serviceAccountKey.json");

        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                .setDatabaseUrl("https://controller-39c7e.firebaseio.com/")
                .build();
        FirebaseApp.initializeApp(options);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Climate.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            serviceAccount.close();
        } catch (IOException ex) {
            Logger.getLogger(Climate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

And I put the file itself here:

enter image description here

However I don't think this is the problem, I have added the dependencies in netbeans and like I said it runs in the IDE. Any help will be much appreciated.

EDIT:

Here is the pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.FUJCode</groupId>
<artifactId>climate2.0</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>5.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-server-sdk</artifactId>
        <version>3.0.3</version>
    </dependency>
</dependencies>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>UsageMoniter</name>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>Climate</mainClass>

                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>   

KENdi
  • 7,576
  • 2
  • 16
  • 31

0 Answers0