如何使一个模块依赖于maven多模块中的另一个模块工件 [英] how to make one module depends on another module artifact in maven multi-modules
问题描述
您好
我有maven多模块项目。
A:parent。
B:child1。
C:child2。
B将被打包以获取jar文件,然后c将使用此jar文件来编译代码。 B中的
如果我运行mvn包,它将创建b.jar(保持在 B / target / jars 不在B / target - 为了另一个目的)。在C中,我需要使用该b.jar来编译代码。
现在,从A,当我运行:mvn包。首先,我成功地为B创建b.jar文件。
但是当它来到C的编译阶段。它看起来像C在类路径中不识别b.jar(编译得到错误,因为C'code不能从B导入类文件)。我的问题是我如何解决这个问题?
---------- bellow是pom文件
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>
<依赖关系>
<依赖关系>
< groupId> AAA< / groupId>
< artifactId> B< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< / dependency>
....
看起来像应该对我工作但是您可以尝试使用 mvn install
而不是 mvn package
。
Hi I have maven multiple-module project.
A: parent.
B: child1.
C: child2.
B will be packaged to get jar file and then c will use this jar file to compile the code.
in B, if i run mvn package, it will create b.jar (stays in B/target/jars not in B/target -for another purpose).
in C, i need to use that b.jar to compile the code.
Now, from A, when i run: mvn package. First, i am successful to create b.jar file for B. But when it come to C's compilation phase. it look like C doesn't recognize b.jar in classpath (the compilation gets errors because C'code can not import the class file from B). My question is how i can solve this problem?
---------- bellow 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>
....
Looks like it should work to me. But you might try mvn install
instead of mvn package
.
这篇关于如何使一个模块依赖于maven多模块中的另一个模块工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!