Maven - how to add a module in parent project'

2019-08-04 16:59发布

I have a situation mentioned in this question.

I have a multi-module Maven project with a parent project P and two sub-modules A and B. When I only had A as a sub module it worked fine. I added a new source folder in the main project, created a package and added a class (am i doing something wrong here?), lets call it module B. Now i import the class in package B in a class in package A, but A's pom doesnt get updated to include B as dependency and thus when I try to mvn compile the parent project it gives the error undefined symbol B.

  1. Am I adding project B wrongly? coz it doesnt have any pom in it?
  2. How do I add B as dependency in main project's pom file as mentioned in the referenced question?

Edit: Adding poms and code

here is project A's pom

<dependencies>
    <dependency>
      <groupId>javax.slee</groupId>
      <artifactId>jain-slee</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mobicents.servers.jainslee.core</groupId>
      <artifactId>fault-tolerant-ra-api</artifactId>
      <version>2.6.0.FINAL</version>
    </dependency>
    <dependency>
      <groupId>org.mobicents</groupId>
      <artifactId>hello-slee-world-sbb</artifactId>
      <version>1.0</version>
    </dependency>
</dependencies>

nowwhere it has B's dependency mentioned. Here is the reference of B in project A.

import BPackage.*;

this is how I have used B in A.

there is only one class in BPackage named BClass. Now I am asking if I am adding the package wrongly i.e. do I need to maven add some thing? so that its pom gets created and its dependency is added in A.

Furthermore I want to build both B and A when I compile the parent so in that case I guess I need to add A in parents pom as well. Here is the parent's pom

  <modules>
    <module>sbb</module>
    <module>customRAType-ratype</module>
    <module>customAdaptor-ra</module>
    <module>du</module>
  </modules>

customAdaptor-ra is project A

1条回答
做自己的国王
2楼-- · 2019-08-04 17:43

Each of your projects needs to have a pom.xml. The top-level project needs to have

<modules>
   <module>project1</module>
   <module>project2</module>
</modules>

If project2 depends on project1, you need to define a <dependency/> to it inside project2's pom.xml.

查看更多
登录 后发表回答