java -jar app.jar
)运行时,我收到错误消息:
Unable to initialize main class RSocketClient.Client
Caused by: java.lang.NoClassDefFoundError: io/rsocket/transport/ClientTransport
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>
<groupId>org.example</groupId>
<artifactId>RSocketSample</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>RSocketClient.Client</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.rsocket</groupId>
<artifactId>rsocket-core</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>io.rsocket</groupId>
<artifactId>rsocket-transport-netty</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>
</project>
看起来您的 jar 不包含 RSocket 本身的类,这很好。Maven 创建的 Jar 仅包含您的类(在您的模块中)。
rsocket 的 jar(以及您正在使用的其他 jar,例如 SLF4J 的东西)驻留在由这些第三方的维护者准备的相应 jar 中。
IntelliJ“看到”整个类路径(包括所有依赖项)并使用所有这些类路径运行您的应用程序。
可能您应该做的是创建一个包含依赖项的 jar:请参阅此 SO 线程
另一种选择是保持你的 jar “原样”,但要求它将与类路径中的所有依赖项一起运行,但它看起来不是你想要做的,这种方式在你开发库时使用而不是独立的应用程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句