Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

917
Views
Discord bot JDA doesn't work, caused by java.lang.ClassNotFoundException

I am trying to build a discord bot with the Java Discord API, but when I run this code snippet:

public static void main(String[] args) throws LoginException {
    JDABuilder builder = JDABuilder.createDefault(token);
    builder.setActivity(Activity.watching("boop"));
    builder.build();
}

It throws this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: gnu/trove/map/TLongObjectMap
at net.dv8tion.jda@4.2.0_216/net.dv8tion.jda.api.entities.Activity.watching(Activity.java:204)
at rambot/rambot.discord.MainApp.main(MainApp.java:14)Caused by: java.lang.ClassNotFoundException: gnu.trove.map.TLongObjectMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more

Why is this being thrown, and how can I fix it?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

For people who see this, but can't seem to read the comments or figure it out on their own. On the JDA wiki, there is an explanation as well. Credits to @BENRABAH Brahim Zaky

NoClassDefFoundError or ClassNotFoundException on startup
An error like java.lang.NoClassDefFoundError: net/dv8tion/jda/api/JDABuilder or similar means you are not including your dependencies or transitive dependencies in the archive.

Gradle (build.gradle)
With gradle this can be fixed by using the shadow plugin and building your jar with shadowJar instead. The jar will then be present in the build/libs directory with a name like example-1.0-all.jar

Maven (pom.xml)
With maven you need the shade plugin in your pom to add dependencies to your package task. You can see the shade plugin being applied in this example pom.xml

Jar (No build tools)
You need to use the -withDependencies.jar rather than the normal one.

The preferred method depends per programmer, but I suggest using either gradle or maven. Since they do everything from compiling your Jar to adding the dependencies.

over 4 years ago · Santiago Trujillo Report

0

I had the same issue too, this error is caused since your compiler didn't found the class path

my solution:

you have to delete the (JDA) from Modulepath and add it to Classpathh inside the (java build path).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!