2010-11-16 76 views
2

目前,我想排除從默認的src/main/resources文件夾到我的抗戰一些文件打包Maven的 - 從默認的src排除某些資源文件到WAR /主/資源位置

,當我試圖使用maven -war-plugin具有以下配置但失敗。

<webResources> 
    <resource> 
    <directory>src/main/resources</directory> 
    <targetPath>WEB-INF/classes</targetPath> 
    <excludes> 
     <exclude>*.xml</exclude> 
    </excludes> 
    </resource> 
</webResources> 

... WEB-INF/classes仍將包含XML文件。

怎麼辦呢?

+0

只需將它們移動到除src/main/resources之外的其他位置 – khmarbaise 2010-11-16 10:54:36

+0

這可能是您要查找的內容:http://stackoverflow.com/questions/3750189/maven2-excluding-directory-from-war – 2011-04-13 11:54:36

回答

0

從戰爭的Maven插件的documentation,您可以包括和排除資源如下:

... 
     <configuration> 
      <webResources> 
      <resource> 
       <!-- the default value is ** --> 
       <includes> 
       <include>**/pattern1</include> 
       <include>*pattern2</include> 
       <includes> 
       <!-- there's no default value for this --> 
       <excludes> 
       <exclude>*pattern3/pattern3</exclude> 
       <exclude>pattern4/pattern4</exclude> 
       </excludes> 
      </resource> 
      </webResources> 
     </configuration> 
     ... 

你這之後,它仍然無法正常工作?如果是這樣,你可以發佈你的pom片段嗎?

+0

1如果使用以下: \t \t \t \t \t \t \t \t \t \t \t \t ** /的log4j.xml \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t $ {BASEDIR}/src目錄/主/ web應用 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t **/osirisws-servlet.xml中 \t \t \t \t \t \t \t \t \t **/osirisws-servlet.xml中,** /的log4j.xml user509392 2010-11-17 03:45:53

+0

得到異常: [INFO]在org.apache.maven.plugin.war.AbstractWarMojo跟蹤 顯示java.lang.NullPointerException 。 copyResources(AbstractWarMojo.java:395) at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:325) at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java: 167) 在org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:133) 在org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483) 在 – user509392 2010-11-17 03:49:21

+0

2.如果使用以下 \t \t \t \t \t \t \t $ {BASEDIR}/SRC /主/資源 WEB-INF /類 \t \t \t \t \t \t \t \t \t \t \t ** /的log4j.xml \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t $ {BASEDIR}/src目錄/主/ web應用 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t **/osirisws-servlet.xml中 \t \t \t \t \t \t \t \t \t \t **/osirisws-servlet.xml,**/log4j.xml user509392 2010-11-17 03:53:39

4

https://stackoverflow.com/a/2737635/722997指出,一個快速的方法來從war包中排除文件是排除他們在build->resources部分,如:

<build> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <excludes> 
       <exclude>*.xml</exclude> 
      </excludes> 
     </resource> 
    </resources> 
    ... 
</build> 

注意:考慮到下面的配置將僅影響Maven(WAR包,JAR包,...)的默認執行,但不影響程序集或其他用戶配置。

0

這是有點晚了這個問題,但我只是試圖做同樣的事情,並且已經發現(與Maven的戰爭插件3.1.0版本),並補充說:

<packagingExcludes>WEB-INF/classes/*.xml</packagingExcludes> 

到配置應該做什麼要求(它工作我刪除屬性文件,我們不想與戰爭文件分發)。