Cannot find main class when running jar file built with maven

52 Views Asked by At

I have recently been making my first discord bot in java(JDA). Everything was going well until I tried to build the bot into a runnable jar file so I can host the bot on a server. I can build the file using 'mvn package' but whenever I go to run the jar file I get an error saying "Could not find or load main class". I tried adding a field to my pom.xml file but it did not work. Here is a copy of my pom.xml file and a screenshot of my file structure.

<?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.tommy.tombot</groupId>
    <artifactId>JDA-TomBot</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>JDA-TomBot</name>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>5.0.0-beta.18</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            
                            <mainClass>com.tommy.tombot.TomnutBot</mainClass>
                        </manifest>
                    </archive>

                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

enter image description here

I tried adding a mainClass field to my pom.xml file, however I am very inexperienced when it comes to maven and pom.xml files.

0

There are 0 best solutions below