0

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

我也根据他们阅读了其他文章,有时在运行时找不到外部 jar 文件路径,因此我们需要 java 类路径(源附件)。所以我通过 Build path > jar > added source attachment 添加。但仍然是在运行时找不到该类。

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>

错误页面:

错误页面

4

1 回答 1

0

在 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>

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

于 2020-06-17T12:27:57.933 回答