【发布时间】:2020-12-04 06:48:36
【问题描述】:
我是 maven 的菜鸟,我正在尝试将一个外部 jar 附加到我的项目中。 所以我的 ${project.basedir}\src\lib 文件夹中有一个 x.jar 依赖项,这是我的项目所必需的。
当我运行mvn clean install 时,它成功完成。
当我运行java -jar project-1.0-SNAPSHOT.jar 时,我得到了错误
线程“主”java.lang.NoClassDefFoundError 中的异常:
我的 pom 文件是:
<?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>project</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>x.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>x</groupId>
<artifactId>x</artifactId>
<version>RELEASE</version>
<systemPath>${project.basedir}/src/lib/x.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
</project>
我应该如何运行 maven 或编辑我的 pom 来解决这个问题?
【问题讨论】: