Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

920
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda