我正在構建一個帶有內置插件加載器的spring boot websocket應用程式,但是當我打包并運行jar時,它給出了這個錯誤:
Error: Could not find or load main class io.github.omen.Main
Caused by: java.lang.ClassNotFoundException: io.github.omen.Main
我通過測驗發現插件加載器和 websocket 應用程式都作為單獨的專案作業,但不會一起加載。下面是我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>
uj5u.com熱心網友回復:
請在 spring-boot-maven-plugin 中配置 mainClass 并洗掉 maven-assembly-plugin。嘗試如下:
<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>
uj5u.com熱心網友回復:
最快的解決方案是:
到 Spring Initializer:https ://start.spring.io/
使用您喜歡的版本生成一個新的 Maven / Java / SpringBoot 專案。
運行它并檢查您的系統是否正常
開始在此專案中一次添加一個自定義項,并在每次修改后嘗試。
幾分鐘后,您將找到此錯誤背后的原因。
如果你使用 spring-boot-maven-plugin 那么你不需要 maven-assembly-plugin
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/514511.html
標籤:爪哇春天弹簧靴行家罐
