java - Spring boot (Maven) 运行时未找到外部 jar 类

标签 java spring-boot maven maven-plugin executable-jar

我在运行 jar 时收到 classNotFound 。此类存在于通过构建路径添加的外部 jar 中。在出现编译时错误之前,我在 pom.xml 中添加了以下代码。所以现在我没有收到编译时错误,但现在我在运行该可执行 jar 时收到错误。

我也阅读了其他文章,有时在运行时找不到外部 jar 文件路径,因此我们需要 java 类路径(源附件)。所以我通过“构建路径”>“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>

错误页面:

Error Page

最佳答案

在 Maven 依赖项中添加外部 jar 后,它解决了我的问题。

步骤:

  1. 在项目中创建 libs 文件夹。右键单击项目>新建>文件夹>库

  2. 将外部 jar 文件放入该文件夹中。

  3. 打开 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>

通过使用此步骤,我解决了我的问题。

关于java - Spring boot (Maven) 运行时未找到外部 jar 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62389508/

相关文章:

java - 冲突的 JAR : shouldn't WEB-INF/lib take precedence over all others places?

java - 无法在 Spring Boot 中拦截和操作 HttpServletResponse

java - 本地存储库中缺少 tools.jar 会破坏 m2eclipse

java - 错误 :maven-resources-test:twitter_storm_new: java. lang.NegativeArraySizeException

Spring 启动 : Not to use TLSv1. 0

maven - 建立自定义Maven生命周期而不创建插件

java - eclipse 警告 "field declaration hides another field or variable"的使用?

java - 无法找到元素链接

java - DAO 层中的@Cacheable 未被触发(Spring/Redis)

spring-boot - Spring Boot Security hasRole 不起作用