[英]Spring boot project could not find or load main class
I am building a spring boot websocket application with a plugin loader built into it but when I package and run the jar it gives this error:我正在构建一个 spring 引导 websocket 应用程序,其中内置了一个插件加载器,但是当我 package 并运行 jar 时,它给出了这个错误:
Error: Could not find or load main class io.github.omen.Main
Caused by: java.lang.ClassNotFoundException: io.github.omen.Main
I've found by testing that both the plugin loader and the websocket app work as separate projects but will not load together.我通过测试发现插件加载器和 websocket 应用程序作为单独的项目工作,但不会一起加载。 Below is my
pom.xml
, thank you in advance.下面是我的
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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.github.omen</groupId>
<artifactId>OmenChat</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- plugin api -->
<dependency>
<groupId>com.github.OMEN44</groupId>
<artifactId>OMENChat-plugin-api</artifactId>
<version>4bf005d4ac</version>
</dependency>
<!-- lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<!-- logger-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.3</version>
</dependency>
<!-- spring boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>io.github.omen.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Please configure mainClass in spring-boot-maven-plugin and remove maven-assembly-plugin.请在 spring-boot-maven-plugin 中配置 mainClass 并移除 maven-assembly-plugin。 Try as below:
尝试如下:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<mainClass>io.github.omen.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
The fastest solution is:最快的解决方案是:
Got to Spring Initializer: https://start.spring.io/得到 Spring 初始化器: https://start.spring.io/
Generate a new Maven / Java / SpringBoot project with version you prefer.使用您喜欢的版本生成一个新的 Maven / Java / SpringBoot 项目。
run it and check your system is fine运行它并检查您的系统是否正常
start adding your customizations one at a time in this project, and try after each modification.开始在此项目中一次添加您的自定义项,并在每次修改后尝试。
In few minutes you'll have found the reason behind this error.几分钟后您就会找到此错误背后的原因。
And if you are using spring-boot-maven-plugin then you don't need maven-assembly-plugin如果你使用的是 spring-boot-maven-plugin 那么你不需要 maven-assembly-plugin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.