【发布时间】:2021-11-04 09:45:39
【问题描述】:
我需要使用 spring-boot-maven-plugin 为我的项目构建一个 jar 文件。当我构建一个没有模块的项目时,一切都解决了。我决定尝试同样的事情,但已经在一个多模块项目中。结果,我收到了这个错误: 找不到主类
这是我的父 Pom.xml:
<project>
<groupId>org.example</groupId>
<artifactId>Project Name</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>Controller</module>
<module>Model</module>
<module>View</module>
<module>Execute</module>
</modules>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
ru.kwork.Main
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
...
</dependencies>
</project>
这里是子 Pom.xml:
<project>
<parent>
<artifactId>Project Name</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>Model</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
<project>
<parent>
<artifactId>Project Name</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>Controller</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>Model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
<project>
<parent>
<artifactId>Project Name</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>View</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>Controller</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
<project>
<parent>
<artifactId>Project Name</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>Execute</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>View</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
主类位于 Execute 模块中。
我在类似的问题中看到他们添加到子问题 Pom.xml 这里是这个插件:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
但这对我没有帮助/或我做错了什么。 我也在网上看到了一些解决方案,但我不明白。我希望你能帮助我解决这个问题并找出解决方案。谢谢。
【问题讨论】:
-
您是否尝试过在
spring-boot-maven-plugin上不使用<executions> (...) </executions>配置? -
@JoãoDias,没有。然后在哪里指定主类?
-
在 Spring Boot 中,您使用
@SpringBootApplication标记主类。此类必须具有通常的public static void main(String[] args)方法。在这里查看一个示例 --> baeldung.com/spring-boot-annotations#spring-boot-application. -
@JoãoDias,我在主类上方有这个注释。
-
@JoãoDias,但它仍然没有帮助。
标签: java spring-boot maven jar multi-module