【发布时间】:2013-10-24 03:04:30
【问题描述】:
我不确定我是否了解如何正确使用父 pom 项目。我定义了以下父 pom:
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../child1</module>
<module>../child2</module>
</modules>
然后子 pom 引用父级(每个子级都有自己的一组依赖项,未显示):
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>child1</artifactId>
此设置工作正常,并在 Eclipse (m2eclipse) 中正确解决。我可以将它们部署到我的本地存储库并最终得到以下结构,这应该是正确的:
--com
--example
--parent
--0.0.1-SNAPSHOT
--parent-0.0.1-SNAPSHOT.pom
--child1
--0.0.1-SNAPSHOT
--child1-0.0.1-SNAPSHOT.jar
--child1-0.0.1-SNAPSHOT.pom
--child2
--0.0.1-SNAPSHOT
--child2-0.0.1-SNAPSHOT.jar
--child2-0.0.1-SNAPSHOT.pom
我的问题是我现在想在 不同 项目(不是 parent、child1 或 child2)中引用 parent 项目,从而拉入所有父母的孩子们。我可以在我的其他项目中添加对它的引用:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
</dependencies>
执行此操作时,项目在 Eclipse 中没有显示任何错误,但没有将工件添加到我的类路径中:不是 child1、child2 或它们的任何依赖项。
我一直认为必须有一种方法来拥有一个“主”pom 项目,它本身不是一个 jar,但只引用其他 jar,然后能够在某处引用该“主”,但我找不到了解这是如何实现的。
【问题讨论】:
标签: java eclipse maven m2eclipse