gpt4 book ai didi

Spring 启动 : can't create war with maven: Unable to find main class

转载 作者:行者123 更新时间:2023-12-03 20:53:45 27 4
gpt4 key购买 nike

我有一个带有 war 和 ear 模块的 SpringBoot 项目,我使用 maven(主要用于 Java 项目的构建自动化工具)和 IntelliJ IDEA 构建该项目。
这是我的 war 项目的 pom.xml

  <?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>
<parent>
<groupId>com.bendiciones</groupId>
<artifactId>bendiciones-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>bendiciones-war</artifactId>
<name>bendiciones war</name>
<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bendicionesbendiciones</groupId>
<artifactId>bendiciones</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>bendiciones</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.bendiciones.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<scm>
<tag>bendiciones-parent-4.0.0-SNAPSHOT</tag>
</scm>
</project>

但是当我建立这个类时,我有这个错误:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage (repackage) on project bendiciones-war: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage failed: Unable to find main class -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage (repackage) on project bendiciones-war: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage failed: Unable to find main class
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)

甚至项目中都存在该类

最佳答案

添加您的 main(starterApplication) 类。 list 中的“Main-Class”实际上是由 Spring Boot plugin 的“布局”属性控制的。 .

    <build>
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.your.starter.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

你需要检查 META-INF/MANIFEST.MF .
Main-Class: org.springframework.boot.loader.WarLauncher
Start-Class: com.your.starter.Application

The Executable War File Structure
example.war
|
+-META-INF
| +-MANIFEST.MF
+-org
| +-springframework
| +-boot
| +-loader
| +-<spring boot loader classes>
+-WEB-INF
+-classes
| +-com
| +-mycompany
| +-project
| +-YourClasses.class
+-lib
| +-dependency1.jar
| +-dependency2.jar
+-lib-provided
+-servlet-api.jar
+-dependency3.jar

或使用父子关系构建。
 <build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

关于 Spring 启动 : can't create war with maven: Unable to find main class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61768002/

27 4 0
文章推荐: python - 在 Python 中使用 Gekko 运行时间序列线性优化
文章推荐: react-native - 如何在 Material 顶部选项卡导航器上方呈现单个标题组件?
文章推荐: typeorm - 类型错误 : Cannot set property EntityManager of# which has only a getter