2012-03-12 185 views
0

我有以下項目: 5個(+)罐子,每個構建特定的組件,具有共同的依賴關係和特定於罐子的依賴關係 1 war(捆綁這些罐子,依賴) 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 

但是,這並不工作,因爲耳朵項目將包括在/ lib文件夾中的父的通用罐子依賴。

這樣的項目怎麼能夠在maven中很好地建立起來?


更新

我還挺由具有根POM其中宣佈了jar1,2個模塊圍繞它的工作,戰爭和耳朵項目,但是必須在jar1,jar2,戰爭從繼承父母pom。耳項目沒有。這是正確的做法嗎?

回答

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等等。這個級別給觀察者一個不一樣的印象。所以你的結構應該代表你的依賴結構。我不確定這是否是您的項目的正確結構,但代表您的依賴關係指導您的結構(文件夾結構)。

0

它應該可以工作,但是你沒有透露你的project-root pom.xml的內容。你在那裏使用「dependencyManagement」,而不是「依賴」?這聽起來不是在使用「dependencyManagement」部分,但是您應該將所有依賴項都提交給所有子模塊。

+0

我想在耳項目中的所有子依賴項_except_中的依賴jar。在耳項目中,我可以通過添加所有模塊來避開這個問題,然後將它們排除在外......但是肯定上面的這樣的設置是很常見的,而且有人擊敗了這個野獸? – 2012-03-12 13:23:28

+0

好吧 - 不,我不認爲這是很常見的有多個工件,都需要包含相同的一組依賴瓶。到目前爲止,最常見的方式是在子pom中指定依賴關係,因爲所有模塊通常都有自己的一組依賴關係。即使在你的情況下,我也會在project-root dependencyManagement部分指定依賴項,然後在jar-1和jar-2中指定依賴項。它還有一個額外的好處,即它的所有依賴關係在模塊級別都是明確的,並且你不必爲此通過root pom。 – eis 2012-03-12 18:33:16

+0

所以,我不會保留它,然後... – 2012-03-13 07:43:33