Maven exec插件找不到mainClass

62lalag4  于 2023-05-16  发布在  Maven
关注(0)|答案(1)|浏览(148)

我正在尝试用java构建一个项目,我正在与maven斗争。当我运行mvn compile时,一切似乎都正常,但当我尝试运行mvn exec:java时,无论我做什么,都会出现相同的错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< MK_Degens:32er_Bot >-------------------------
[INFO] Building 32er_Bot 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ 32er_Bot ---
[WARNING] 
java.lang.ClassNotFoundException: src.com.statsbot.Bot
    at java.net.URLClassLoader.findClass (URLClassLoader.java:445)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:587)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:520)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:270)
    at java.lang.Thread.run (Thread.java:833)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.549 s
[INFO] Finished at: 2023-05-09T13:51:13+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project 32er_Bot: An exception occured while executing the Java class. src.com.statsbot.Bot -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是我的pom.xml:

<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>MK_Degens</groupId>
    <artifactId>32er_Bot</artifactId>
    <version>1.0</version>

    <name>32er_Bot</name>

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

    <dependencies>
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots</artifactId>
            <version>6.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>src.com.statsbot.Bot</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的.java文件在src目录下,第一行是package com.statsbot;。这个类叫做Bot
我需要做什么才能让maven找到我的类?
到目前为止,我已经尝试了运行mvn exec:execmvn clean install,并尝试了所有可能的方法将mainClass放入pom中。

yhqotfr8

yhqotfr81#

默认情况下,您的源代码在src/main/java中,因此您的类应该有一个com.statsbot的包。
文件应该是src/main/java/com/statsbot/Bot.java,开头是package com.statsbot;
你的主类应该在pom.xml中定义:

<mainClass>com.statsbot.Bot</mainClass>

相关问题