J'ai 2 fichiers java:Exception dans le thread "principal" java.lang.NoClassDefFoundError: lors de l'exécution avec la console. Peut-être liées à Maven-
package com.pokebot;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
public class App {
public static void main(String[] args)
{
try {
JDA jdaBot = new JDABuilder(AccountType.BOT).setToken("my_token").buildBlocking();
jdaBot.addEventListener(new Pokebot());
} catch (LoginException e) {
// System.out.println("LoginException");
} catch (InterruptedException e) {
// System.out.println("InterruptedException");
} catch (RateLimitedException e) {
// System.out.println("RateLimitedException");
}
}
}
et:
package com.pokebot;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
public class Pokebot extends ListenerAdapter {
@Override
public void onMessageReceived(MessageReceivedEvent e) {
//Obtains properties of the received message
Message objMsg = e.getMessage();
MessageChannel objChannel = e.getChannel();
User objUser = e.getAuthor();
//Responds to any user who says "hello"
if (objMsg.getContent().equals("hello")) {
objChannel.sendMessage("Hello, " + objUser.getAsMention() +"!").queue();
}
}
}
Quand je lance l'application (la classe principale est App du 1er fichier) de Netbeans, je reçois un seul remarque:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
mais l'application fonctionne toujours. Lorsque je tente de le lancer depuis la ligne de commande:
java -jar target/pokebotapp-1.0-SNAPSHOT.jar
puis-je obtenir une exception comme ceci:
Exception in thread "main" java.lang.NoClassDefFoundError: net/dv8tion/jda/core/exceptions/RateLimitedException
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: net/dv8tion/jda/core/
exceptions/RateLimitedException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: net.dv8tion.jda.core.exceptions.Rat
eLimitedException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Et l'application ne commence même pas. J'utilise Maven pour ce projet. Mon pom.xml:
<?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.pokebot</groupId>
<artifactId>pokebotapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!--<classpathPrefix>lib/</classpathPrefix>-->
<mainClass>com.pokebot.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/dependency-jars/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.3.1_291</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
</project>
Avant d'essayer d'exécuter le projet à partir de la console, je lance maven compile
. Je pense que c'est peut-être la faute de la façon dont je cours le programme, ou de la façon dont j'ai mis en place maven pour ce projet. Y a-t-il quelqu'un qui sait quel peut être le problème?
lire https://stackoverflow.com/questions/7421612/slf4j-failed-to-load-class-org-slf4j-impl-staticloggerbinder – Lokesh
J'ai ajouté des dépendances de Maven pour 'slf4j-api- 1.7.5' et 'slf4j-simple-1.7.5', mais ont toujours le même problème, même après mvn propre installer – Lurker
avez-vous mis à jour votre projet et vérifier l'instantané et les versions des mises à jour de force? – Lokesh