2013-07-10 114 views
3

我有xml文件,其中包含必須由特定值替換的屬性。所以我使用資源過濾來實現這一點。Maven資源過濾不會複製未過濾的文件

這裏是資源結構:

src 
    - main 
     - java 
     - resources 
     - VAADIN 
      -themes 
     - UI.gwt.xml 
     - webapp 
     - WEB-INF 

資源的pom.xml過濾用法:

<resources> 
    <resource> 
     <directory>${basedir}/src/main/resources</directory> 
     <filtering>false</filtering> 
     <includes> 
      <include>**/VAADIN/themes/*</include> 
     </includes> 
     <excludes> 
      <exclude>**/UI.gwt.xml</exclude> 
     </excludes> 
    </resource> 
    <resource> 
     <directory>${basedir}/src/main/resources</directory> 
     <filtering>true</filtering> 
     <includes> 
      <include>**/UI.gwt.xml</include> 
     </includes> 
     <excludes> 
      <exclude>**/VAADIN/themes/*</exclude> 
     </excludes> 
    </resource> 
</resources> 

作爲clean install結果,我接收.war文件與UI.gwt.xml替換屬性,但沒有VAADIN /主題文件夾和它的內容。如果我對<resources>發表評論,則VAADIN/themes將出現在.war文件中,但UI.gwt.xml沒有特定的值。

我的過濾配置有什麼問題?

+0

在所示的目錄結構,我看到VAADIN.themes,但是在配置我們在這兩個資源VAADIN /主題。這是一個錯字嗎?如果不是,那很可能是問題。 – user944849

+0

@ user944849,我使用VAADIN/themes還是VAADIN.themes並不重要。在我的IDE中顯示的是沒有內容的包鏈。但無論如何我都要重新檢查。 – Dragon

+0

@ user944849,用VAADIN.themes重新檢查 - 它仍然不起作用。所以我編輯資源結構不要混淆別人。 – Dragon

回答

3

當在同一directory定義的資源,您可以指定文件,對資源,其中<filtering>true</filtering>使用includes,而其中<filtering>false</filtering>您指定不使用excludes改變文件應用過濾。因此,你的例子將變爲:

<resources> 
    <resource> 
     <directory>${basedir}/src/main/resources</directory> 
     <filtering>true</filtering> 
     <includes> 
      <!-- whatever is defined here will have filters applied --> 
      <include>**/UI.gwt.xml</include> 
     </includes> 
    </resource> 
    <resource> 
     <directory>${basedir}/src/main/resources</directory> 
     <filtering>false</filtering> 
     <!-- everything in this directory remains the same (no filters) --> 
     <excludes> 
      <!-- the excludes found here will be altered by the filters in the first resource set --> 
      <!-- so we need to define them as excluded from the files that should not have filters applied --> 
      <exclude>**/UI.gwt.xml</exclude> 
     </excludes> 
    </resource> 
</resources> 
+0

使用什麼順序並不重要。它仍然不會複製VAADIN主題:( – Dragon

+0

我現在正在閱讀此鏈接的最後一個示例中的警告http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html它似乎是過濾適用於包含的文件,第二條規則告訴它如何處理未過濾的內容。嘗試從已過濾的資源中移除排除 –

+0

是的,我顛倒了過濾的順序(先過濾然後w/o過濾器),並刪除包括與VAADIN主題。因此一切工作,因爲我想。但我仍然不明白爲什麼它的行爲在這種方式:( – Dragon