Solved bukkit+firebase

Discussion in 'Plugin Development' started by ofeking, Mar 12, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    ofeking

    Hi, i try to make a plugin that connect to the real time database of firebase.
    I use intelliJ.
    here is my pom.xml:
    Code:
    <?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.ofeking</groupId>
        <artifactId>YourPixelData</artifactId>
        <version>1.0-SNAPSHOT</version>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>8</source>
                        <target>8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>com.google.firebase</groupId>
                <artifactId>firebase-admin</artifactId>
                <version>6.12.2</version>
            </dependency>
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.6.1</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jetbrains</groupId>
                <artifactId>annotations-java5</artifactId>
                <version>17.0.0</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>
    Sorry for my English, I don't speak English well

    up

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 12, 2020
  2. Offline

    Kars

    And what is your question?
     
  3. Offline

    ofeking

    this is don't work, how can i make it work?
     
  4. Online

    timtower Administrator Administrator Moderator

    What error do you get then?
     
  5. Offline

    ofeking

    This is my code:
    Code:
    static {
            try {
                FirebaseOptions options = new FirebaseOptions.Builder()//line 33
                        .setCredentials(GoogleCredentials.fromStream(new ByteArrayInputStream(key.getBytes())))
                        .setDatabaseUrl("https://yourpixel-32575.firebaseio.com")
                        .build();
    
                FirebaseApp.initializeApp(options);
                PlayerData.init();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    (key is static String, and i don't want to share it)


    This is the error:
    Code:
    13.03 15:10:58 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:138) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:337) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:257) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins(CraftServer.java:355) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:226) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:870) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
    13.03 15:10:58 [Server] INFO Caused by: java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at com.ofeking.minecraft.yourpixel.data.YourPixelDataPlugin.<clinit>(YourPixelDataPlugin.java:33) ~[?:?]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:63) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:134) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO ... 6 more
    13.03 15:10:58 [Server] INFO Caused by: java.lang.ClassNotFoundException: com.google.firebase.FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:139) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:85) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at com.ofeking.minecraft.yourpixel.data.YourPixelDataPlugin.<clinit>(YourPixelDataPlugin.java:33) ~[?:?]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:63) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:134) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:138) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:337) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:257) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins(CraftServer.java:355) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:226) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:870) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
    13.03 15:10:58 [Server] INFO Caused by: java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at com.ofeking.minecraft.yourpixel.data.YourPixelDataPlugin.<clinit>(YourPixelDataPlugin.java:33) ~[?:?]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:63) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:134) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO ... 6 more
    13.03 15:10:58 [Server] INFO Caused by: java.lang.ClassNotFoundException: com.google.firebase.FirebaseOptions$Builder
    13.03 15:10:58 [Server] INFO at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:139) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:85) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at com.ofeking.minecraft.yourpixel.data.YourPixelDataPlugin.<clinit>(YourPixelDataPlugin.java:33) ~[?:?]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_222]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:63) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    13.03 15:10:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:134) ~[Paper-1.14.4-b177.jar:git-Paper-176]
    The jar that i export contains only my code and the plugin.yml
     
    Last edited: Mar 13, 2020
  6. Offline

    Kars

    @ofeking try running 'mvn clean install' from the command line in your project directory. That's all i can think of. I have no experience with firebase.

    Does it work in any other projects?
     
  7. Offline

    ofeking

    @Kars
    this is work if i don't use plugin (just run it)
    what is 'mvn clean install'?
     
  8. Offline

    Machine Maker

    Also, make sure in your pom.xml you don't have the <scope>provided</scope> in your firebase depen
     
  9. Offline

    ofeking

  10. Offline

    Kars

    Yea, okay. So you can't access the firebase API from Bukkit. You need a connector of some sort.
     
  11. Offline

    ofeking

    @Kars so how i do that?
     
  12. Offline

    Kars

    @ofeking i dont have experience with this. But i had the same problem trying to run a spring application from a plugin. Spring needs to be run a certain way. Probably is the same way with firebase.

    Either that or you just can't access the dependency somehow.
     
  13. Offline

    ofeking

    @Kars i think that the problem is that i access the dependency.
    this is my first plugin with maven, and i don't know exactly how maven work.
    i use maven because this is the single way to use firebase.
    the jar don't contains only my code and the plugin.yml.
    i think that the problam is that the maven don't export the firebase.
     
  14. Offline

    Kars

    @ofeking Yea exactly. It is the same way with spring. But some guy wrote a connector for bukkit and spring, which made it work. You could try searching for a firebase one.
     
  15. Offline

    ofeking

    I succeeded, the problem was that i didn't export the firebase but now the jar is big (37MG). Can i save some space?
    Sorry for my English.
     
  16. Online

    timtower Administrator Administrator Moderator

    @ofeking Then you would need to decrease the firebase api, which is not possible.
     
  17. Offline

    ofeking

    but maybe is possible to export only what i need.
    is it?
     
  18. Online

    timtower Administrator Administrator Moderator

    You use the entire thing though and nothing is clever enough to strip away what you don't need.
     
  19. Offline

    ofeking

    OK, so how i close this post?
     
  20. Online

    timtower Administrator Administrator Moderator

    No need to close it.
    Marked it as solved.
     
Thread Status:
Not open for further replies.

Share This Page