Reputation: 754
I have two spring-boot projects in Eclipse.
keygenerator-service has dependency on commons-lib so I have built commons-lib first and jar got created successfully in m2 folder. Then I have mentioned the dependency on keygenerator-service's pom.xml file like below.
<dependency>
<groupId>com.abz</groupId>
<artifactId>commons-lib</artifactId>
<version>1.0.0</version>
</dependency>
jar file is present as C:\Users\snsur.m2\repository\com\abz\commons-lib\1.0.0\commons-lib-1.0.0.jar and looks good.
But now when I am trying to do maven build of keygenerator-service getting below errors:
[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
I could see the package exists in the jar file as well.
C:\Users\snsur\Documents\Work\SWs\jdk-11.0.11\bin>jar tvf C:\Users\snsur\.m2\repository\com\abz\commons-lib\1.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
I have checked many stackoverflow link for this type of issue but nothing works for me. I even deleted .m2 folder and freshly built the commons-lib project but still no luck.
Please help me to successfully build keygenerator-service with commons-lib jar.
Upvotes: 0
Views: 950
Reputation: 754
After getting the suggestion from Thorbjorn , I have resolved like this in commons-lib pom.xml
(For spring boot 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>
Now it is working as dependency / library.
Upvotes: 0
Reputation: 75426
This is a runnable spring boot jar.
Making it runnable destroys its ability to be used as a dependency (notice the path prefixes)
Fix: only do this to the final jar you want to run.
Upvotes: 2