java.lang.NoClassDefFoundError: com/mongodb/client/MongoClients

5 days ago 5
ARTICLE AD BOX

Based on a few different StackOverflow posts, this is what I came to:

The NoClassDefFoundError can mean a few different things. Among them, it can mean that the classes the plugin depends on were available at compile time, but were not included in the runtime jar. I didn't understand what that meant at first, but after some digging, this turned out to be my case.

If you run "jar tf build/libs/[my-plugin].jar", you'll see what classes were included in your jar file. In my case, the only classes present were the classes I had created. None of the MongoDB classes were in there.

To include those files, I ended up with a slightly modified version of the code in this answer. This code goes inside the tasks section of build.gradle.kts

jar { manifest { attributes( "Main-Class" to "com.example.plugin.mainClass" ) } duplicatesStrategy = DuplicatesStrategy.EXCLUDE from( configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) } ) }

And with that change, the plugin finally recognized MongoDB.

Rhombus17's user avatar

1 Comment

What you're creating here is a so-called "fat", "uber", or "shadowed" JAR file. That's a JAR file that embeds the dependencies' code alongside the project's code (a "shadowed" JAR may also involve namespace changes to avoid conflicts). Another way to accomplish this is to apply the Gradle Shadow Plugin and execute its shadowJar task. I don't know if Minecraft plugins support multiple JAR files, but an alternative approach to embedding dependencies is to ship the dependencies' JAR files alongside your project's JAR file.

2026-04-29T20:05:11.233Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article