0

Am making a Discord bot and I want the bot file in "jar" format so I can run it effectively, but every time I try to build a jar file out of it throws some sort of error, Such as

Error: Could not find or load main class com.Sahil.Main Caused by:java.lang.ClassNotFoundException: com.Sahil.Main

or

Error: Could not find or load main class com.Sahil.Main

First, it used to show the second error but after spending some time on youtube I made some changes and I think it got worse. I've never tried maven so completely blind.

my project structure

pom file

<groupId>org.example</groupId>
<artifactId>Bot</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
</properties>

<dependencies>

</dependencies>

I removed my dependencies as I believe they won't be necessary for this, please do let me know if I need to provide them will do so.

  • [How can I create an executable JAR with dependencies using Maven?](//stackoverflow.com/q/574594) – Tom Aug 10 '21 at 14:46

1 Answers1

0

This error indicates that your jar file does not contain the class file that the JVM tries to invoke main in.

If you look inside your jar file (it is just a zip file) you will most likely find that it does not contain a file with the exact name com/Sahil/Main.class.

Fix your jar creation so that file is present. You will then find that it cannot find classes from your dependencies. That is a different problem with several solutions. As @Tom suggests, look at How can I create an executable JAR with dependencies using Maven? to find out which one suits you best.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347