MongoDB Issues.

Discussion in 'Spigot Plugin Development' started by Confinement, Apr 18, 2017.

  1. Code (Text):
    [15:03:28 ERROR]: Error occurred while enabling Ekko v1.0-RELEASE (Is it up to date?)
    java.lang.NoClassDefFoundError: com/mongodb/MongoClient
            at com.alexandeh.ekko.Ekko.setupDatabase(Ekko.java:147) ~[?:?]
            at com.alexandeh.ekko.Ekko.onEnable(Ekko.java:61) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:477) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:395) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:354) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:328) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:284) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:227) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:493) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-PaperSpigot-43]
    Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClient
            at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-PaperSpigot-43]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_121]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_121]
            ... 13 more
     
    I get this error message when I start up the server and it can't find MongoClient.

    Here is the main class:

    Code (Text):
    package com.alexandeh.ekko;

    import com.alexandeh.ekko.factions.Faction;
    import com.alexandeh.ekko.factions.claims.ClaimListeners;
    import com.alexandeh.ekko.factions.claims.ClaimPillar;
    import com.alexandeh.ekko.factions.commands.*;
    import com.alexandeh.ekko.factions.commands.admin.FactionAdminCommand;
    import com.alexandeh.ekko.factions.commands.admin.FactionFreezeCommand;
    import com.alexandeh.ekko.factions.commands.admin.FactionSetDtrCommand;
    import com.alexandeh.ekko.factions.commands.admin.FactionThawCommand;
    import com.alexandeh.ekko.factions.commands.leader.FactionDemoteCommand;
    import com.alexandeh.ekko.factions.commands.leader.FactionDisbandCommand;
    import com.alexandeh.ekko.factions.commands.leader.FactionLeaderCommand;
    import com.alexandeh.ekko.factions.commands.leader.FactionPromoteCommand;
    import com.alexandeh.ekko.factions.commands.officer.*;
    import com.alexandeh.ekko.factions.commands.system.FactionColorCommand;
    import com.alexandeh.ekko.factions.commands.system.FactionCreateSystemCommand;
    import com.alexandeh.ekko.factions.commands.system.FactionToggleDeathbanCommand;
    import com.alexandeh.ekko.factions.type.PlayerFaction;
    import com.alexandeh.ekko.files.ConfigFile;
    import com.alexandeh.ekko.listeners.ChatListeners;
    import com.alexandeh.ekko.listeners.ScoreboardListeners;
    import com.alexandeh.ekko.profiles.Profile;
    import com.alexandeh.ekko.profiles.ProfileListeners;
    import com.alexandeh.ekko.utils.command.CommandFramework;
    import com.alexandeh.ekko.utils.player.PlayerUtility;
    import com.alexandeh.ekko.utils.player.SimpleOfflinePlayer;
    import com.mongodb.MongoClient;
    import com.mongodb.MongoCredential;
    import com.mongodb.ServerAddress;
    import com.mongodb.client.MongoDatabase;
    import lombok.Getter;
    import lombok.Setter;
    import net.milkbowl.vault.economy.Economy;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.io.IOException;
    import java.util.Arrays;

    @Getter
    public class Ekko extends JavaPlugin {

        private static Ekko instance;

        private CommandFramework framework;
        private ConfigFile mainConfig;
        private ConfigFile langConfig;
        private Economy economy;
        private MongoClient client;
        private MongoDatabase mongoDatabase;
        @Setter private boolean loaded;

        public void onEnable() {
            instance = this;

            mainConfig = new ConfigFile(this, "config");
            langConfig = new ConfigFile(this, "lang");

            setupDatabase();
            Faction.load();

            framework = new CommandFramework(this);
            economy = Bukkit.getServer().getServicesManager().getRegistration(Economy.class).getProvider();

            SimpleOfflinePlayer.load(this);
            PlayerFaction.runTasks(this);

            registerListeners();
            registerCommands();
        }

        public void onDisable() {
            Faction.save();

            for (Player player : PlayerUtility.getOnlinePlayers()) {
                Profile profile = Profile.getByUuid(player.getUniqueId());
                if (profile.getClaimProfile() != null) {
                    profile.getClaimProfile().removePillars();
                }
                for (ClaimPillar claimPillar : profile.getMapPillars()) {
                    claimPillar.remove();
                }
                player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
            }

            try {
                SimpleOfflinePlayer.save(this);
            } catch (IOException e) {
                e.printStackTrace();
            }

            client.close();
        }

        private void registerCommands() {
            new FactionHelpCommand();
            new FactionDisbandCommand();
            new FactionCreateCommand();
            new FactionVersionCommand();
            new FactionInviteCommand();
            new FactionJoinCommand();
            new FactionRenameCommand();
            new FactionPromoteCommand();
            new FactionDemoteCommand();
            new FactionLeaderCommand();
            new FactionUninviteCommand();
            new FactionChatCommand();
            new FactionSetHomeCommand();
            new FactionMessageCommand();
            new FactionAnnouncementCommand();
            new FactionLeaveCommand();
            new FactionShowCommand();
            new FactionKickCommand();
            new FactionInvitesCommand();
            new FactionAllyCommand();
            new FactionEnemyCommand();
            new FactionDepositCommand();
            new FactionWithdrawCommand();
            new FactionClaimCommand();
            new FactionMapCommand();
            new FactionUnclaimCommand();
            new FactionListCommand();
            new FactionHomeCommand();
            new FactionStuckCommand();
            new FactionCreateSystemCommand();
            new FactionToggleDeathbanCommand();
            new FactionColorCommand();
            new FactionFreezeCommand();
            new FactionThawCommand();
            new FactionSetDtrCommand();
            new FactionAdminCommand();
        }

        private void registerListeners() {
            Bukkit.getPluginManager().registerEvents(new ProfileListeners(), this);
            Bukkit.getPluginManager().registerEvents(new ScoreboardListeners(), this);
            Bukkit.getPluginManager().registerEvents(new ChatListeners(), this);
            Bukkit.getPluginManager().registerEvents(new ClaimListeners(), this);
        }

        private void setupDatabase() {
            if (mainConfig.getBoolean("DATABASE.MONGO.AUTHENTICATION.ENABLED")) {
                client = new MongoClient(new ServerAddress(mainConfig.getString("DATABASE.MONGO.HOST"), mainConfig.getInt("DATABASE.MONGO.PORT")), Arrays.asList(MongoCredential.createCredential(mainConfig.getString("DATABASE.MONGO.AUTHENTICATION.USER"), mainConfig.getString("DATABASE.MONGO.AUTHENTICATION.DATABASE"), mainConfig.getString("DATABASE.MONGO.AUTHENTICATION.PASSWORD").toCharArray())));
            } else {
                client = new MongoClient(new ServerAddress(mainConfig.getString("DATABASE.MONGO.HOST"), mainConfig.getInt("DATABASE.MONGO.PORT")));
            }

            mongoDatabase = client.getDatabase(mainConfig.getString("DATABASE.MONGO.DATABASE"));
        }

        public static Ekko getInstance() {
            return instance;
        }
    }
     
    Any questions, any ideas?
     
  2. Your JAR does not include the MongoDB library?
     
    • Like Like x 1
  3. Sorry forgot to point out that I have three jars in my build path:
    - mongodb-driver-core-3.4.2
    - mongo-java-driver-3.4.2
    - bson-3.4.2
     
  4. Use maven and shade them into your jar (will increase their size quite a lot)
     
    • Like Like x 1
  5. The reason I was building it manually is because I for some reason can't build with maven. Every time I run it this error comes up: C:\Users\Pat\.m2\repository\net\milkbowl\vault\VaultAPI\1.4\VaultAPI-1.4.jar; error in opening zip file
     
  6. the Vault repo doesn't work for me
     
  7. Looks like you have a local repo. Why's that?

    EDIT:
    Code (Text):
    <repository>
        <id>vault-repo</id>
        <url>http://nexus.hc.to/content/repositories/pub_releases</url>
    </repository>
    works just fine
     
    • Like Like x 1
  8. pretty sure I have that already:


    Code (Text):
    <repositories>
            <repository>
                <id>stealthyone-repo</id>
                <url>http://repo.stealthyone.com/content/groups/public</url>
            </repository>
            <repository>
                <id>md5-repo</id>
                <url>http://repo.md-5.net/content/groups/public/</url>
            </repository>
            <repository>
                <id>vault-repo</id>
                <url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.7.10-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.mongodb</groupId>
                <artifactId>mongodb-driver</artifactId>
                <version>LATEST</version>
            </dependency>
            <dependency>
                <groupId>net.milkbowl.vault</groupId>
                <artifactId>VaultAPI</artifactId>
                <version>1.4</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>mkremins</groupId>
                <artifactId>fanciful</artifactId>
                <version>0.3.3-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.14.8</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
     
  9. This is the entire error:

    Code (Text):
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.840s
    [INFO] Finished at: Tue Apr 18 15:55:22 EDT 2017
    [INFO] Final Memory: 9M/245M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Ekko: Compilation failure: Compilation failure:
    [ERROR] error: error reading C:\Users\Pat\.m2\repository\net\milkbowl\vault\VaultAPI\1.4\VaultAPI-1.4.jar; error in opening zip file
    [ERROR] error: error reading C:\Users\Pat\.m2\repository\com\google\code\gson\gson\2.1\gson-2.1.jar; error in opening zip file
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
     
     
  10. You must build your maven project including these dependencies.

    I use this command for that:
    Code (Text):
    clean package assembly:single
     
    • Like Like x 1
  11. I get the same error
     
  12. Ok just to be sure. Heres my entire pom.xml:

    Code (Text):
    <?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.alexandeh.ekko</groupId>
        <artifactId>Ekko</artifactId>
        <version>1.0-RELEASE</version>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <minimizeJar>true</minimizeJar>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

        <repositories>
            <repository>
                <id>stealthyone-repo</id>
                <url>http://repo.stealthyone.com/content/groups/public</url>
            </repository>
            <repository>
                <id>md5-repo</id>
                <url>http://repo.md-5.net/content/groups/public/</url>
            </repository>
            <repository>
                <id>vault-repo</id>
                <url>http://nexus.hc.to/content/repositories/pub_releases</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.7.10-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.mongodb</groupId>
                <artifactId>mongodb-driver</artifactId>
                <version>LATEST</version>
            </dependency>
            <dependency>
                <groupId>net.milkbowl.vault</groupId>
                <artifactId>VaultAPI</artifactId>
                <version>1.4</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>mkremins</groupId>
                <artifactId>fanciful</artifactId>
                <version>0.3.3-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.14.8</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>


    </project>
     
  13. You have all of your dependencies scopes on "provided", doesn't this mean that there's a local file somewhere rather than an online repo? That would be all wrong. Try getting rid of all of those scopes instead of the ones you really only have locally.
     
  14. Think that is false.
     
  15. The vault part is fixed. Any idea what the correct repository for gson 2.1 is cause im still getting that error.
     
  16. Code (Text):
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.728s
    [INFO] Finished at: Tue Apr 18 16:09:44 EDT 2017
    [INFO] Final Memory: 11M/206M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Ekko: Compilation failure
    [ERROR] error: error reading C:\Users\Pat\.m2\repository\com\google\code\gson\gson\2.1\gson-2.1.jar; error in opening zip file
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
     
  17. Update: fixed the two dependency errors. Now I get this error.

    Code (Text):
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 25.859s
    [INFO] Finished at: Tue Apr 18 16:16:02 EDT 2017
    [INFO] Final Memory: 23M/340M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project Ekko: Error reading assemblies: No assembly descriptors found. -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
     
  18. You don't have any assembly descriptor.

    For example:
    Code (Text):
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
     
  19. Alright so setting it up with maven worked fine. It compiled. But heres the error im getting

    Code (Text):

    [17:17:02 ERROR]: Error occurred while enabling Ekko v1.0-RELEASE (Is it up to date?)
    java.lang.NoClassDefFoundError: com/mongodb/MongoClient
            at com.alexandeh.ekko.Ekko.setupDatabase(Ekko.java:149) ~[?:?]
            at com.alexandeh.ekko.Ekko.onEnable(Ekko.java:63) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:477) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:395) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:868) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.Bukkit.reload(Bukkit.java:301) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot.jar:git-PaperSpigot-43]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:766) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1044) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:881) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:789) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:638) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-PaperSpigot-43]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-PaperSpigot-43]
    Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClient
            at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-PaperSpigot-43]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-PaperSpigot-43]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_121]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_121]
            ... 23 more
     
     
  20. Make sure you are shading the MongoDB driver in to the jar.