由于依赖包不存在而依赖包实际存在,因此 maven 构建失败
maven build is failing due to dependency package does not exist while dependency package actually exists
我在 Eclipse 中有两个 spring-boot 项目。
- 公共库
- 密钥生成器服务
keygenerator-service 依赖于 commons-lib,所以我首先构建了 commons-lib,并且在 m2 文件夹中成功创建了 jar。然后我提到了对 keygenerator-service 的 pom.xml 文件的依赖,如下所示。
<dependency>
<groupId>com.abz</groupId>
<artifactId>commons-lib</artifactId>
<version>1.0.0</version>
</dependency>
jar 文件作为 C:\Users\snsur.m2\repository\com\abz\commons-lib.0.0\commons-lib-1.0.0.jar 并且看起来不错。
但是现在当我尝试对 keygenerator-service 进行 maven 构建时出现以下错误:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Drive D/Projects/workspace-backend/workspace1/keygenerator-service/src/main/java/com/abz/keygenerator/core/KeyStore.java:[13,33] package com.abz.commons.exception does not exist
[ERROR] /C:/Drive D/Projects/workspace-backend/workspace1/keygenerator-service/src/main/java/com/abz/keygenerator/core/KeyStore.java:[14,33] package com.abz.commons.exception does not exist
我可以看到该包也存在于 jar 文件中。
C:\Users\snsur\Documents\Work\SWs\jdk-11.0.11\bin>jar tvf C:\Users\snsur\.m2\repository\com\abz\commons-lib.0.0\commons-lib-1.0.0.jar
0 Thu Jul 29 21:33:44 IST 2021 META-INF/
358 Thu Jul 29 21:33:44 IST 2021 META-INF/MANIFEST.MF
.....
0 Thu Jul 29 21:33:46 IST 2021 BOOT-INF/classes/com/abz/commons/exception/
0 Thu Jul 29 21:33:46 IST 2021 BOOT-INF/classes/com/abz/commons/model/
INF/classes/com/abz/commons/exception/AlreadyExistsException.class
INF/classes/com/abz/commons/exception/InvalidDataException.class
我已经检查了很多 Whosebug link 以解决此类问题,但对我没有任何帮助。我什至删除了 .m2 文件夹并重新构建了 commons-lib 项目,但仍然没有成功。
请帮助我使用 commons-lib jar 成功构建密钥生成器服务。
这是一个运行可用的spring启动jar。
使其成为 运行nable 会破坏其用作依赖项的能力(注意路径前缀)
修复:仅对您想要 运行 的最终 jar 执行此操作。
在得到Thorbjorn的建议后,我在commons-lib中这样解决了pom.xml
(对于spring开机2.x)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
现在它作为依赖项/库工作。
我在 Eclipse 中有两个 spring-boot 项目。
- 公共库
- 密钥生成器服务
keygenerator-service 依赖于 commons-lib,所以我首先构建了 commons-lib,并且在 m2 文件夹中成功创建了 jar。然后我提到了对 keygenerator-service 的 pom.xml 文件的依赖,如下所示。
<dependency>
<groupId>com.abz</groupId>
<artifactId>commons-lib</artifactId>
<version>1.0.0</version>
</dependency>
jar 文件作为 C:\Users\snsur.m2\repository\com\abz\commons-lib.0.0\commons-lib-1.0.0.jar 并且看起来不错。
但是现在当我尝试对 keygenerator-service 进行 maven 构建时出现以下错误:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Drive D/Projects/workspace-backend/workspace1/keygenerator-service/src/main/java/com/abz/keygenerator/core/KeyStore.java:[13,33] package com.abz.commons.exception does not exist
[ERROR] /C:/Drive D/Projects/workspace-backend/workspace1/keygenerator-service/src/main/java/com/abz/keygenerator/core/KeyStore.java:[14,33] package com.abz.commons.exception does not exist
我可以看到该包也存在于 jar 文件中。
C:\Users\snsur\Documents\Work\SWs\jdk-11.0.11\bin>jar tvf C:\Users\snsur\.m2\repository\com\abz\commons-lib.0.0\commons-lib-1.0.0.jar
0 Thu Jul 29 21:33:44 IST 2021 META-INF/
358 Thu Jul 29 21:33:44 IST 2021 META-INF/MANIFEST.MF
.....
0 Thu Jul 29 21:33:46 IST 2021 BOOT-INF/classes/com/abz/commons/exception/
0 Thu Jul 29 21:33:46 IST 2021 BOOT-INF/classes/com/abz/commons/model/
INF/classes/com/abz/commons/exception/AlreadyExistsException.class
INF/classes/com/abz/commons/exception/InvalidDataException.class
我已经检查了很多 Whosebug link 以解决此类问题,但对我没有任何帮助。我什至删除了 .m2 文件夹并重新构建了 commons-lib 项目,但仍然没有成功。
请帮助我使用 commons-lib jar 成功构建密钥生成器服务。
这是一个运行可用的spring启动jar。
使其成为 运行nable 会破坏其用作依赖项的能力(注意路径前缀)
修复:仅对您想要 运行 的最终 jar 执行此操作。
在得到Thorbjorn的建议后,我在commons-lib中这样解决了pom.xml
(对于spring开机2.x)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
现在它作为依赖项/库工作。