2013-07-10 195 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