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

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

问题描述

我有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似乎无法在类路径中识别b.jar(编译会出错,因为C的代码无法从B导入类文件).

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?

---------- Below是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天全站免登陆