2013-04-22 17 views
5

我使用Maven的战争插件构建.war文件如何从我的Maven构建资源排除在外,packagingExcludes不工作

我使用packagigExcludes,它工作正常的.jar文件:

<packagingExcludes>WEB-INF/lib/jetty-*.ja       
         WEB-INF/../resources/log4j.properties, 
         WEB-INF/../resources/web.properties 
        </packagingExcludes> 

但属性文件上面没有得到已排除,我也试过:

src/main/resources/web.properties 

这是一个多模块Maven项目,和我一m为这个春天mvc maven项目构建一个.war文件,我必须排除这些文件,但它不起作用。

任何指针?

回答

9

我只是想你...你确定你正在做的配置在正确的地方?我的聚甲醛是这样的:

<?xml version="1.0"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.example</groupId> 
     <artifactId>example-parent</artifactId> 
     <version>0.1.4-SNAPSHOT</version> 
    </parent> 
    <artifactId>example-webapp</artifactId> 
    <packaging>war</packaging> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
     [...] 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> 
       </configuration> 
      </plugin> 
     </plugins> 
     <finalName>example-webapp</finalName> 
    </build> 
</project> 

---->编辑

到exlude从资源的东西,你就必须做到这一点:

  <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <packagingExcludes> 
         WEB-INF/classes/log4j.properties 
        </packagingExcludes> 
       </configuration> 
      </plugin> 
+0

但是你甚至不试图从资源文件夹中排除资源?就像我的例子中的web.properties一样。 .jar文件也适用于我。 – Blankman 2013-04-22 03:44:23

+1

是的 - 但保重!资源实际上并不在资源中......东西来自/ src/main /资源敌人进入/ WEB-INF/classes /所以你可能想排除\t \t \t \t \t WEB-INF/classes/log4j.properties改为 rmalchow 2013-04-22 03:47:55

+0

。下面的解决方案首先阻止这些文件被复制(从src到目标),所以它可能也会起作用。 – rmalchow 2013-04-22 03:48:42

2

添加这pom.xml

</build> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <excludes> 
       <exclude>web.properties</exclude> 
      </excludes 
     </resource> 
    </resources> 
</build> 
+0

对不起忘了提,我使用该maven战争插件来建立一个.war文件,我仍然应该尝试吗? – Blankman 2013-04-22 03:41:45

+0

是的<!------------> – 2013-04-22 03:45:58

+0

好吧,如果您记住src/main/resources的内容被复制到$ {target}/WEB- INF/classes /,所以你必须排除这些路径,而不是源文件夹中的路径。 – rmalchow 2013-04-22 03:52:00