Maven-如何在父项目的pom中添加模块作为依赖项 [英] Maven - how to add a module in parent project's pom as dependency

查看:1772
本文介绍了Maven-如何在父项目的pom中添加模块作为依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问题中提到了这种情况.

I have a situation mentioned in this question.

我有一个多模块Maven项目,其中有一个父项目P和两个子模块A和B.当我只有A作为子模块时,它可以正常工作.我在主项目中添加了一个新的源文件夹,创建了一个包并添加了一个类(我在这里做错了吗?),我们将其称为模块B.现在,我将包B中的类导入到包A中的类中,但是A的pom不会更新为包括B作为依赖项,因此当我尝试mvn编译父项目时,它会给出错误的未定义符号B.

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. 我错误地添加了项目B吗?因为它没有任何pom?
  2. 如所提到的问题中所述,我如何将B作为依赖项添加到主项目的pom文件中?

添加pom和代码

这是项目A的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>

现在提到B的依赖项.这是项目A中B的参考.

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

import BPackage.*;

这就是我在A中使用B的方式.

this is how I have used B in A.

在BPackage中只有一个名为BClass的类.现在我要问我是否错误地添加了软件包,即我是否需要Maven添加一些东西?这样就可以创建它的pom并将其依赖项添加到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.

此外,我想在编译父对象时同时构建B和A,因此在这种情况下,我想我也需要在父pom中添加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是项目A

customAdaptor-ra is project A

推荐答案

您的每个项目都需要具有pom.xml.顶级项目必须具有

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>

如果project2依赖于project1,则需要在project2的pom.xml中为其定义一个<dependency/>.

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

这篇关于Maven-如何在父项目的pom中添加模块作为依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆