Java Gradle erreur lors du lancement

Fermé
Krafty - Modifié le 26 nov. 2022 à 16:04
 Krafty - 4 déc. 2022 à 13:50

Bonjour,

J'essaye de développer un bot Discord... En Java.

Je sais que ce n'est pas très commun, et peut-être pas très opti, mais je voulais voir si c'était possible, et je suis plus à l'aise en Java qu'en Python ou Javascript.

Bref, je cogne sur un bug totalement incompréhensible. (Ne vous inquiétez pas, le bug n'a pas trop de lien avec Discord, c'est juste Java et Gradle qui marche pas)

Dès que je lance mon programme Gradle, le lancement s'arrête. Le message d'erreur me dit que la classe Main est introuvable ou ne peut pas être chargée, alors qu'elle est belle et bien dans mon package dans le dossier "src".

Voici le message d'erreur avec --info en paramètre : 

13:22:25: Executing 'run --info'...

Starting Gradle Daemon...
Gradle Daemon started in 4 s 975 ms
The client will now receive all logging from the daemon (pid: 36346). The daemon log file: /Users/lydiejullien/.gradle/daemon/6.8/daemon-36346.out.log
Starting build in new daemon [memory: 512 MiB]
Using 4 worker leases.
Watching the file system is disabled
Starting Build
Settings evaluated using settings file '/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/settings.gradle'.
Projects loaded. Root project using build file '/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/build.gradle'.
Included projects: [root project 'Kraftys Bot']

> Configure project :
Evaluating root project 'Kraftys Bot' using build file '/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/build.gradle'.
All projects evaluated.
Selected primary task 'run' from project :
Tasks to be executed: [task ':compileJava', task ':processResources', task ':classes', task ':run']
Tasks that were excluded: []
:compileJava (Thread[Execution worker for ':' Thread 2,5,main]) started.

> Task :compileJava NO-SOURCE
file or directory '/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/src/main/java', not found
Skipping task ':compileJava' as it has no source files and no previous output files.
:compileJava (Thread[Execution worker for ':' Thread 2,5,main]) completed. Took 0.141 secs.
:processResources (Thread[Execution worker for ':' Thread 2,5,main]) started.

> Task :processResources NO-SOURCE
file or directory '/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/src/main/resources', not found
Skipping task ':processResources' as it has no source files and no previous output files.
:processResources (Thread[Execution worker for ':' Thread 2,5,main]) completed. Took 0.006 secs.
:classes (Thread[Execution worker for ':' Thread 2,5,main]) started.

> Task :classes UP-TO-DATE
Skipping task ':classes' as it has no actions.
:classes (Thread[Execution worker for ':' Thread 2,5,main]) completed. Took 0.003 secs.
:run (Thread[Execution worker for ':' Thread 3,5,main]) started.

> Task :run FAILED
Caching disabled for task ':run' because:
  Build cache is disabled
Task ':run' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Starting process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java''. Working directory: /Users/lydiejullien/Java/discord_workspace/Kraftys Bot Command: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -Duser.country=FR -Duser.language=fr -Duser.variant -cp /Users/lydiejullien/Java/discord_workspace/Kraftys Bot/build/classes/java/main:/Users/lydiejullien/Java/discord_workspace/Kraftys Bot/build/resources/main:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/net.dv8tion/JDA/4.1.1_101/6f26dec69ff0af77e0b3b64b1e3e83bb5bf188b1/JDA-4.1.1_101.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/16.0.1/c1a6655cebcac68e63e4c24d23f573035032eb2a/annotations-16.0.1.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.25/da76ca59f6a57ee3102f8f9bd9cee742973efa8a/slf4j-api-1.7.25.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.neovisionaries/nv-websocket-client/2.9/7e4cc077330c2c45d25390507ed27e958a1eae9a/nv-websocket-client-2.9.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.squareup.okhttp3/okhttp/3.13.0/f53f6362226e4546c3987b8693f3d6976df8c797/okhttp-3.13.0.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/club.minnced/opus-java/1.0.4/596995aaf2f5b5091c4d251fdc11fa62680cc59e/opus-java-1.0.4.pom:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-collections4/4.1/a4cf4688fe1c7e3a63aa636cc96d013af537768e/commons-collections4-4.1.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/net.sf.trove4j/trove4j/3.0.3/42ccaf4761f0dfdfa805c9e340d99a755907e2dd/trove4j-3.0.3.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.10.1/18eee15ffc662d27538d5b6ee84e4c92c0a9d03e/jackson-databind-2.10.1.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.squareup.okio/okio/1.17.2/78c7820b205002da4d2d137f6f312bd64b3d6049/okio-1.17.2.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/club.minnced/opus-java-api/1.0.4/20e4fafa8523ed391446ddc7dff60ef832f1543a/opus-java-api-1.0.4.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/club.minnced/opus-java-natives/1.0.4/292d015243833578eda04b1ad0af2dc351b14b1b/opus-java-natives-1.0.4.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.10.1/54d72475c0d6819f2d0e9a09d25c3ed876a4972f/jackson-annotations-2.10.1.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.10.1/2c8b5e26ba40e5f91eb37a24075a2028b402c5f9/jackson-core-2.10.1.jar:/Users/lydiejullien/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/4.4.0/cb208278274bf12ebdb56c61bd7407e6f774d65a/jna-4.4.0.jar Bot.java
Successfully started process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java''
:run (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 1.234 secs.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
1 actionable task: 1 executed
Erreur : impossible de trouver ou de charger la classe principale Bot.java
Causé par : java.lang.ClassNotFoundException: Bot.java

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
13:22:41: Execution finished 'run --info'.

Voici le code de ma classe Bot (la classe contenant la méthode main) : 

package fr.krafty.botdiscord;

import javax.security.auth.login.LoginException;

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;

public class Bot {

	public static void main(String[] args) throws LoginException {
		JDABuilder builder = new JDABuilder(AccountType.BOT);
		builder.setToken(args[1]);
		builder.addEventListeners(new Application());
		builder.build();
	}
}

Et voici enfin un screenshot de l'arborescence de mon projet :

Merci de m'avoir écouté,

En espérant que vous saurez que dois-je faire,

Krafty ^^
Macintosh / Chrome 107.0.0.0

A voir également:

1 réponse

KX Messages postés 16739 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 19 mai 2024 3 016
27 nov. 2022 à 16:09

Bonjour,

Quel est le contenu du fichier Gradle ?

Vu l'erreur je devine qu'au moment de déclarer la classe main, il doit être mentionné Bot.java au lieu de fr.krafty.botdiscord.Bot


1

Oooh merci, je savais pas qu'il fallait mettre le package de la classe aussi ! Comme je l'avais déjà mis ailleurs (dans settings.gradle ou build.gradle, je sais plus, et j'ai pas mon ordinateur de disponible pour le moment)

Je n'avais effectivement mis que Bot.java.

Merci pour votre réponse, je testerais de nouveau quand je pourrais et je dirais si ça marche ^^

Merci,

Krafty

0