如何使一个模块依赖于另一个模块工件? [英] How to make one module depend on another module artifact?

查看:36
本文介绍了如何使一个模块依赖于另一个模块工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 maven 多模块项目.

I have maven multiple-module project.

 A: parent.
    B: child1.
    C: child2.

B 会被打包得到 jar 文件,然后 c 会使用这个 jar 文件来编译代码.

B will be packaged to get jar file and then c will use this jar file to compile the code.

在 B 中,如果我运行 mvn package,它将创建 b.jar(停留在 B/target/jars 不在 B/target - 用于其他目的).

In B, if I run mvn package, it will create b.jar (stays in B/target/jars not in B/target -for another purpose).

在 C 中,我需要使用 b.jar 来编译代码.

In C, I need to use that b.jar to compile the code.

现在,从 A,当我运行:mvn package.首先,我成功地为 B 创建了 b.jar 文件.

Now, from A, when I run: mvn package. First, I am successful to create b.jar file for B.

但是到了C的编译阶段,貌似C在classpath中不能识别b.jar(编译出错是因为C的代码不能从B导入class文件).

But when it come to C's compilation phase, it looks like C doesn't recognize b.jar in the classpath (the compilation gets errors because C's code can not import the class file from B).

我的问题是:我该如何解决这个问题?

My question is: How can I solve this problem?

---------- 下面是pom文件

---------- Below are the pom files

A: pom.xml
  <groupId>AAA</groupId>
  <artifactId>A</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

   <modules>
   <module>C</module>
   <module>B</module>
   </modules>

B: pom.xml
        <groupId>AAA</groupId>
 <artifactId>B</artifactId>
 <packaging>jar</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <parent>
  <artifactId>A</artifactId>
  <groupId>AAA</groupId>
  <version>0.0.1-SNAPSHOT</version>
 </parent>

C: pom.xml
       <parent>
  <artifactId>A</artifactId>
  <groupId>AAA</groupId>
  <version>0.0.1-SNAPSHOT</version>
 </parent>

 <groupId>AAA</groupId>
 <artifactId>C</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>

 <dependencies>

  <dependency>
   <groupId>AAA</groupId>
   <artifactId>B</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency>
....

推荐答案

看起来应该对我有用.但是你可以试试 mvn install 而不是 mvn package.

Looks like it should work to me. But you might try mvn install instead of mvn package.

这篇关于如何使一个模块依赖于另一个模块工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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