我在运行jar时得到classNotFound。此类存在于通过构建路径添加的外部jar中。在出现编译时错误之前,我在pom.xml中添加了以下代码。所以现在我没有遇到编译时错误,但是现在运行该可执行jar时却出现了错误。
我也根据他们阅读了一些其他文章,有时在运行时找不到外部jar文件路径,因此我们需要java classpath(源附件)。所以我通过构建路径> jar>添加了源附件添加了。但是仍然没有在运行时找到该类。
Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
com.main.Application
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
错误页面:
在maven依赖项中添加了外部jar之后,它解决了我的问题。
步骤:
在您的项目中创建libs文件夹。右键单击项目>新建>文件夹>库
将您的外部jar文件放入该文件夹。
打开pom.xml文件,并将该依赖项添加到您的代码中。
jar名称:ReleaseVersion.jar
<dependency>
<groupId>ReleaseVersion</groupId>
<artifactId>ReleaseVersion</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}/libs/ReleaseVersion.jar</systemPath>
</dependency>
通过使用此步骤,我解决了我的问题。