Maven设置了战争,耳朵和依赖性罐子

时间:2012-03-12 10:40:11

标签: maven war ear

我有以下项目: 5(+)个jar,每个构建特定的组件,具有公共依赖项和jar特定的依赖项 1战争(捆绑这些罐子及其依赖) 1耳(持有战争,战争)

我如何很好地融入maven?

我进行了以下设置:

    project-root.pom
     |- generic jar dependency 1
     |- generic jar dependency 2
     |- modules
         | - jar 1 (uses generic dependencies, and a couple of others)
         | - jar 2 (uses generic dependencies, and a couple of others)
         | - war project (uses generic jars, and jar 1 and 2)
         | - ear project

但这不起作用,因为ear项目将包含/ lib文件夹中父项的通用jar依赖项。

如何在maven中很好地设置这样的项目?


更新

我有点通过一个根pom来解决它,它为jar1,2,war和ear项目声明了模块,但只有jar1,jar2和war继承自父pom。耳朵项目没有。这是正确的做法吗?

2 个答案:

答案 0 :(得分:0)

它应该可以工作,但是你没有透露项目根pom.xml的内容。你在那里使用“dependencyManagement”,而不仅仅是“依赖”吗?听起来你不是在使用“dependencyManagement”部分,但你应该,不要将所有的依赖关系都提供给所有的子模块。

答案 1 :(得分:0)

你潦倒的结构让我对你的项目结构有了不同的感受。让我来描述一下。如果我看到如下结构,我会假设:

project-root.pom
  |- generic jar dependency 1 (parent: project-root.pom)
  |- generic jar dependency 2 (parent: project-root.pom)
  |- modules
      +-- module-pom
      | - jar 1 (uses generic dependencies, and a couple of others) (parent:module-pom)
      | - jar 2 (uses generic dependencies, and a couple of others)(parent:module-pom)
      | - war project (uses generic jars, and jar 1 and 2) (parent:module-pom)
      | - ear project (parent:module-pom)

但是你在文中描述了模块的不同关系:

root
 |- generic jar dependency 1
 |- generic jar dependency 2
 |- jar 1 (uses generic dependencies, and a couple of others)
 |- jar 2 (uses generic dependencies, and a couple of others)
 |- ear project
 |- war project (uses generic jars, and jar 1 and 2)

使用上述结构,您可以简单地定义战争中的依赖关系,例如依赖于jar-1,jar-2。耳朵只取决于战争。 jar-1可能依赖于泛型jar依赖性1,依此类推。这些关卡为观察者提供了与项目不同的印象。所以你的结构应该代表你的依赖结构。我不确定这是否是您项目的正确结构,但是表示您的依赖关系引导您的结构(文件夹结构)。