2013-02-14 65 views
0

我試圖利用maven-war-plugin的有用疊加功能。 換句話說,我有一個模板(打包爲WAR文件,template-0.0.1.war),其中包含標籤文件,css,js和圖像。maven-war-plugin overlay和m2e eclipse插件

當我設置template-0.0.1.war爲MyApp項目的依賴,我得到含那些在MyApp項目相同的路徑覆蓋了的template-0.0.1.war所有文件最終myApp.war

這是我想要的行爲。

不過,我需要在對myApp的pom.xml的Maven的戰爭插件的配置介紹:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <webResources> 
     <resource> 
      <directory>../path/to/another/dir</directory> 
     </resource> 
     </webResources> 
    </configuration> 
</plugin> 

只要我介紹的插件這樣的配置,我獲得最終myApp.war與來自template-0.0.1.war和myApp項目的所有文件,但template-0.0.1.war的文件覆蓋myApp項目中具有相同路徑的文件。

這種行爲與我所期望的完全相反。

有人能告訴我我哪裏錯了嗎?

在此先感謝。該解決方案後

編輯發現:

所描述的問題是由於不同的動作的併發:戰爭的覆蓋(其中正常工作)和外部webResources

實際上,外部webResources標記指向模板項目目錄:對Maven完全沒有用處,但對於「愚弄」m2e eclipse插件並讓它看到模板中包含的自定義標記是不可或缺的。

我所採用的解決方案是在我的pom.xml的插件部分引進2個不同的配置文件:稱爲「」我在其中插入maven-war-pluginwebResources和第二輪廓(稱爲「標準的第一個「並且默認激活)而不是maven-war-plugin

回答

0

maven war plugin documentation

默認情況下,該項目的源(a.k.a當前構建)首先加入(施加任何覆蓋例如之前)。當前版本被定義爲沒有groupId,artifactId的特殊疊加。如果需要首先應用疊加層,則只需在疊加層之後配置當前的構建。

如果模板中的文件被子WAR中的文件覆蓋,則可能需要考慮在覆蓋配置中明確排除它們。

這裏的文件說,首先應用覆蓋什麼:

<build> 
<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <overlays> 
     <overlay> 
      <groupId>com.example.projects</groupId> 
      <artifactId>my-webapp</artifactId> 
     </overlay> 
     <overlay> 
      <!-- empty groupId/artifactId represents the current build --> 
     </overlay> 
     </overlays> 
    </configuration> 
    </plugin> 
</plugins> 

+0

您的快速回答非常感謝,但它不解決問題(見我的文章編輯)。只有在昨天晚上,我意識到這個問題是由於不同的行爲相互壓倒。這是我的罪過,我沒有提供完整的信息。抱歉。 – baronKarza 2013-02-15 07:53:49