1
votes

There is spring application "A" packaged as JAR (with maven) and the POM file of application "A" contain few particular maven dependencies defined.

In another spring boot application "B" packaged as JAR, the dependency of application "A" is added, but at the time of execution of "B", it throws few ClassNotFound/NoClassDef errors for the dependencies mentioned in application "A".

Note - application "A" is not a boot project. It is a simple spring app build with maven.

Please assist. Please let me know, if I need to share any code w.r.to this. Thanks in advance.

1
Hi Pinaki, I ran into this spring boot dependency issue a couple of weeks ago. The problem stems from bringing in a boot executable JAR into your project instead of a jar containing the actual class files. baeldung.com/spring-boot-dependency - Connor

1 Answers

0
votes

Spring boot jar is not really a jar and its the core issue here. Its only packed as jar for convenience, but if you open it (with WinRaR/WinZip or with any other program) you'll see that it doesn't have a structure of JAR, for example, all dependencies are included into the JAR (see BOOT-INF/lib).

So, bottom line, if both A and B are spring boot applications you cannot make a dependency between them, it won't work.

As a solution consider extracting the code that should be shared into a third module "C" that will have packaging jar but won't be by itself a spring boot application.

Afterwards make both A and B depend on C and you're set