简体   繁体   中英

java.lang.NoClassDefFoundError: com/mongodb/XXXXXX Can't fix it! (Using: MongoDB Java Driver, Spigot)

I'm writing a plugin for Spigot/Bukkit (Minecraft) in Java and can't figure out how to fix this problem for the life of me. Although I have done a lot of programming in other languages, this is my first attempt at programming in java. I have done many google searches, looked at dozens of pages, but everything just said to do things I have already tried.

I'm using eclipse and have converted my project to and from a maven project trying all sorts of variations of installing the mongo java driver. I've tried:
- Adding dependency/s
- Adding it to the buildpath using project->properties->Java Build Path->Add External Jar
- I've done a combination of both of the above
- I've tried using mongodb-driver, mongodb-driver-core and bson together, and with mongodb-java-driver(which should just work on it's own.)
- I've tried just using mongodb-java-driver
- I've tried using many different versions of the drivers.

It doesn't matter what I do, when I export my plugin to a jar and attempt to run it on my spigot server I get the following error:

java.lang.NoClassDefFoundError: com/mongodb/MongoClientURI

Where MongoClientURI could be replaced by any mongo class I use in my code. Am I not using the driver correctly, am I missing something? What's going on?

So I solved my own problem in the end. Turns out spigot doesn't recognize any jar files other than spigot plugins on execution. Shading would've solved my issue but instead I did this, which also works:

  1. Created a file called MANIFEST.MF within my project directory.
  2. Added the following to the file:

    Manifest-Version: 1.0
    Class-Path: libs/mongo-java-driver-3.2.2.jar
    Created-By: 1.7.0_06 (Oracle Corporation)

  3. Selected "Use existing manifest from workspace" in the final step of exporting my plugin.

This meant that at runtime spigot would include {plugin location}/libs/mongo-java-driver-3.2.2.jar in it's libraries.

I found my solution here: https://www.spigotmc.org/threads/solved-mongodb-help.35922/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM