Maven - 在最终的WAR中不包含src / main / webapp的某个子目录

时间:2012-05-30 14:57:10

标签: java maven maven-war-plugin

maven 2.2.1

您好, 我有这棵主干树:

.
├── pom.xml
├── src
│   ├── main
│   │   └── webapp
│   │       ├── META-INF
│   │       ├── **resources**
│   │       │   ├── **bootstrap**
│   │       │   │   ├── **bootstrap**
│   │       │   │   │   ├── css
│   │       │   │   │   ├── img
│   │       │   │   │   └── js
│   │       │   │   ├── docs
│   │       │   │   ├── img
│   │       │   │   ├── js
│   │       │   │   ├── less
│   │       │   │   ├── LICENSE
│   │       │   │   ├── Makefile
│   │       │   │   ├── package.json
│   │       │   │   └── README.md
│   │       │   ├── cms
│   │       │   └── **static**
│   │       │       ├── css
│   │       │       ├── feeds
│   │       │       ├── img
│   │       │       ├── js
│   │       │       └── less
│   │       ├── WEB-INF

我用double *突出显示了有趣的目录......

在打包时,我正在尝试将resources/bootstrap排除在resources/bootstrap/boostrap内的最终WAR 复制resources/static之外。

换句话说,我需要获得以下内容:

.
│   │       ├── META-INF
│   │       ├── **resources**
│   │       │   ├── cms
│   │       │   └── **static**
│   │       │       ├── **bootstrap**
│   │       │       │   ├── css
│   │       │       │   ├── img
│   │       │       │   └── js
│   │       │       ├── css
│   │       │       ├── feeds
│   │       │       ├── img
│   │       │       ├── js
│   │       │       └── less
│   │       ├── WEB-INF

我不幸地弄乱了maven-war-plugin,但我仍然无法获得理想的结果。

这是我的pom相关部分的最新版本:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <packagingExcludes>WEB-INF/**.tld</packagingExcludes>
        <warSourceExcludes>resources/bootstrap</warSourceExcludes>
        <webResources>
            <resource>
                <!-- this is relative to the pom.xml directory -->
                <directory>src/main/webapp/resources/bootstrap</directory>
                <!-- override the destination directory for this resource -->
                <targetPath>resources/static</targetPath>
                <includes>
                    <include>bootstrap/**</include>
                </includes>
            </resource>
        </webResources>                 
    </configuration>
</plugin>

提前感谢您提供任何后续提示!

1 个答案:

答案 0 :(得分:2)

你很亲密;您需要为resources/bootstrap/**参数指定warSourcesExcludes以省略整个树(目录及其所有子目录)。仅排除resources/bootstrap目录不会执行任何操作,因为它仍包含该目录的所有子项,在复制子项时自动创建目录且父目录不存在。

所以你的配置应该有:

    <configuration>
        ...
        <warSourceExcludes>resources/bootstrap/**</warSourceExcludes>
        ...
    </configuration>

并且在再次打包战争之前不要忘记运行Maven clean

相关问题