我正在尝试使用Maven构建的依赖性运行JAR。依赖性已安装在本地存储库中,只是将依赖性添加到pom.xml ..它已成功编译,但在Runruntime中获得classNotFound exception。我在互联网上探索了,但没有运气
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>XYZ</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>WEB-INF/classes/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.xyz.Abc</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>localrepository</id>
<url>${user.home}/.m2/repository</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.abc</groupId>
<artifactId>jarname</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
创建一个运行"任何地方"的jar,可以创建一个可执行的jar:
如何使用maven创建具有依赖项的可执行罐?
否则,您需要小心班级路径,因为否则Java找不到您的依赖。