2

给定一个 Maven 项目 A 生成一个 jar:

<groupId>myprojects</groupId>
<artifactId>A</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>some.needed.group</groupId>
        <artifactId>some.needed.artifact1</artifactId>
    </dependency>
    <dependency>
        <groupId>some.needed.group</groupId>
        <artifactId>some.needed.artifact2</artifactId>
    </dependency>
</dependencies>

和项目 B 依赖于 A 并生成企业档案:

<groupId>myprojects</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<dependencies>
    <dependency>
        <artifactId>A</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

我怎样才能让项目 B 的耳朵工件不仅包括项目 B 的 jar 工件,而且还包括它的依赖工件 some.needed.artifact1 和 some.needed.artifact2?


我编辑并添加了这个,因为似乎该行为仅在从 Bamboo 运行 mvn 时发生:奇怪的是,当我从 Eclipse 本地运行 mvn 时它正在工作,但当它由 Bamboo 持续集成服务器运行时却没有。在本地运行中,我使用对所有传递依赖项的引用正确生成了 application.xml,并将相应的 jar 文件复制到 lib 文件夹。在 Bamboo 计划中,生成的 application.xml 不包含引用,并且 jar 文件不在 lib 文件夹中。

4

2 回答 2

1

首先作为更正,我认为依赖应该在 A 上,而不是在 B 上,如下所示:

   <dependencies>
    <dependency>
        <artifactId>A</artifactId>
        <version>1.0</version>
    </dependency>
 </dependencies>

关于拥有依赖 jar 的原始问题,我认为它们应该在您的 EAR 文件中可用,因为您依赖A project并且依赖于some.needed.artifact1 and some.needed.artifact2(传递依赖),因为您提供的范围是默认的,所以 maven 会将其视为编译,所有的 jar 包都会打包到你的 ear 文件中。

谢谢

于 2013-08-01T19:57:59.450 回答
-1

在产生耳朵的项目 B 中,您可以像这样包含对 A 的依赖项

<modules>
  <module>project A</module>
</modules>
<dependencies>
  <dependency>
    <groupId>some.needed.group</groupId>
    <artifactId>A</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

在项目 A 中,将父项目定义为项目 B,如下所示

<parent>
        <groupId>myprojects</groupId>
        <artifactId>B</artifactId>
        <version>1.0</version>
        <name>project B</name>
</parent>
<name>project A</name>
于 2013-08-01T20:05:34.960 回答