我的 Spring Boot 项目。我的项目中有一个外部 jar 文件,并且仅通过构建路径添加。当我使用 Maven clean install 命令运行我的项目时。我收到以下错误消息:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[16,33] package com.omnesys.nestq.classes does not exist
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[17,33] package com.omnesys.nestq.classes does not exist
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[36,28] cannot find symbol
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>exec</classifier>
<mainClass>
com.orion.main.NestOrionApplication
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我也阅读了其他文章,有时在运行时找不到外部 jar 文件路径,因此我们需要 java 类路径(源附件)。所以我通过“构建路径”>“jar”>“添加源附件”添加。但我仍然遇到相同的编译错误。
最佳答案
在 Maven 依赖项中添加外部 jar 后,它解决了我的问题。
步骤:
- 在项目中创建 libs 文件夹。右键单击项目>新建>文件夹>库
- 将外部 jar 文件放入该文件夹中。
- 打开 pom.xml 文件并将该依赖项添加到您的代码中。
jar 名称:ReleaseVersion.jar
<dependency>
<groupId>DealerNestQApiReleaseVersion</groupId>
<artifactId>DealerNestQApiReleaseVersion</artifactId>
<scope>system</scope>
<version>1.1</version>
<systemPath>${basedir}/libs/DealerNestQApiReleaseVersion.jar</systemPath>
</dependency>
- 在maven中添加以下代码。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
通过使用此步骤,我解决了我的问题。
关于java - Maven : Package not found when clean install,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62389951/