Maven Subproject Class Access Guide
To call classes from a sub-project, you can declare the sub-project in the parent project’s pom.xml file using tags, and then directly reference the classes from the sub-project in the parent project.
For example, if you have a parent project and a child project, you can declare the child project in the pom.xml file as follows:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>child-project</module>
</modules>
</project>
Then in the parent project, classes from the child project can be directly referenced, for example:
import com.example.childproject.ChildClass;
public class ParentClass {
public static void main(String[] args) {
ChildClass child = new ChildClass();
child.doSomething();
}
}
Ensure that the correct dependencies are configured in the pom.xml file of the subproject so that the parent project can access the classes of the subproject. Typically, you can add dependencies in the pom.xml file of the subproject, for example:
<dependency>
<groupId>com.example</groupId>
<artifactId>child-project</artifactId>
<version>1.0.0</version>
</dependency>
Now you can call the classes of the subproject in the parent project.