Maven - how to add a module in parent project's pom as dependency

自作多情 提交于 2020-01-16 01:00:10

问题


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:


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.



来源:https://stackoverflow.com/questions/14960005/maven-how-to-add-a-module-in-parent-projects-pom-as-dependency

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!