如何解决如何使用Maven修复缺少外部依赖的jar?
我是与maven的亲戚,我正在尝试将一个外部jar附加到我的项目中。 因此,我在项目中需要的 $ {project.basedir} \ src \ lib 文件夹中有一个 x.jar 依赖项。
当我运行mvn clean install
时,它成功完成。
当我运行java -jar project-1.0-SNAPSHOT.jar
时,出现错误
线程“ main”中的异常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才能解决此问题?
解决方法
标准jar不包含依赖项,因此除非您指定完整的类路径,否则无法在命令行上运行。
因此,要么构建一个jar-with-dependencies
(Maven程序插件或Maven阴影插件),要么显式列出依赖项。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。