In the SpringBoot project, when the install name is executed, the console displays: Unable to find main class

Building a springboot multi-module project can start normally at startup, and there is no problem executing the maven clean of the parent project. When executing install, an error is reported: Unable to find main class. Obviously this error is that the main class cannot be found.
insert image description here
Record the solution process:
first check whether the following tags exist in the parent project of your own project:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Because I used the project built on the springboot official website, and then built multiple modules on this basis, it was here at the beginning. I didn't notice that when I executed the install, I reported an error: Unable to find main class. I have this problem because the label is not configured correctly or the position is not placed correctly.

The solution I provide here is as follows, and I have personally verified it:
1: Specify the clean path where the startup class is located in the parent project
:
insert image description here

When installing:
insert image description here
start
insert image description here
2: Put the build tag in the parent project into the pom file where the project with the main program is located (my main program is under the admin package), and put it in the pom file of the project where the main program is located. You need to specify the path where the main program is located. As shown in the figure:
insert image description here
After clean:
insert image description here
After install: insert image description here
Start:
insert image description here
Meaning of tags in plugins in build:

 build中的plugins,它定义了 spring-boot-maven-plugin 插件的使用,这个插件在 Spring Boot 项目中非常重要,它用于将项目打包成可执行的 JAR 文件,并执行其他与 Spring Boot 相关的任务。
     1:<plugin> 标签:这是 Maven 构建工具用来定义插件的起始标签。在这个标签内,可以配置插件的详细信息;
     2:<groupId> 和 <artifactId>:这两个标签指定了插件的坐标(Coordinates),即插件的唯一标识符。在这里,org.springframework.boot 是插件的 Group ID,spring-boot-maven-plugin 是插件的 Artifact ID。这些信息用于在 Maven 仓库中定位并下载插件。
     3:<configuration> 标签:这个标签包含了插件的配置信息。
     4:<mainClass>标签: 指定了 Spring Boot 应用程序的主类,主类是 Spring Boot 应用程序的入口点,即可执行 JAR 文件的入口点,当你运行 JAR 文件时,这个类的 main 方法会被执行。在这个例子中,主类是 com.lucky.PracticeApplication

Record this pit in this way, hoping to help other friends who encounter this problem. Please correct me if the description is wrong. If you have any questions, please add Q: 876942434

Guess you like

Origin blog.csdn.net/fortunate_leixin/article/details/132599535