Maven: How to manage dependency from one child module to another child module

3.9k Views Asked by At

I have maven parent-child project where parent has multiple child modules. One of the child module is generating a jar and other one is depending on that jar.

Project structure is like: One parent module which has three child modules. Each one has its own pom.xml. Child1 generates jar file and others are generating war file. Where only Child3 is dependent on Child1 jar.

Is there a best way to manage such type of dependency using pom.xml.

Project Structure

Updated: When I am adding dependency in Child3 I am able to build Child3 module but when I am trying to deploy it on tomcat it throws an error as:

Caused by: java.lang.NoClassDefFoundError: org/ifxforum/xsd/_1/CIMBAcctInfoInqSvc
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
... 57 more Caused by: java.lang.ClassNotFoundException: org.ifxforum.xsd._1.CIMBAcctInfoInqSvc
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
... 64 more

And my dependency in Child3's pom.xml as:

<dependency>
        <groupId>myGroupId</groupId>
        <artifactId>myArtifactId</artifactId>
        <version>1</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/lib/myJar.jar</systemPath>
    </dependency>

I can see org/ifxforum/xsd/_1/CIMBAcctInfoInqSvc is in jar.

1

There are 1 best solutions below

3
On BEST ANSWER

You just declare a maven dependency in Child3 on the coordinates of Child1. For the version, you can use ${project.version}.